diff --git a/CHANGELOG.md b/CHANGELOG.md index cb016fea..abbb7815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ - **Search on Enter Only**: Removed auto-search debounce, now only searches when pressing Enter key (saves API calls) ### Fixed +- **Android 11 Storage Permission**: Fixed "Permission denied" error on Android 11 (API 30) devices + - Added `MANAGE_EXTERNAL_STORAGE` permission for Android 11-12 + - Shows explanation dialog before opening system settings - **Download Cancel**: Fixed cancelled downloads still completing in background and appearing in history. Cancelled files are now properly deleted. - **Search Keyboard Dismiss**: Fixed keyboard randomly dismissing and navigating back when starting to search - **Back Button During Search**: Back button now properly dismisses keyboard first before clearing search diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 710042c9..bd483d13 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -4,9 +4,11 @@ + android:maxSdkVersion="29" /> + + diff --git a/lib/screens/setup_screen.dart b/lib/screens/setup_screen.dart index d6041381..dccc0374 100644 --- a/lib/screens/setup_screen.dart +++ b/lib/screens/setup_screen.dart @@ -87,10 +87,43 @@ class _SetupScreenState extends ConsumerState { PermissionStatus status; if (_androidSdkVersion >= 33) { + // Android 13+: Use audio permission status = await Permission.audio.request(); } else if (_androidSdkVersion >= 30) { - status = await Permission.manageExternalStorage.request(); + // Android 11-12: Need MANAGE_EXTERNAL_STORAGE + // This opens system settings, not a dialog + status = await Permission.manageExternalStorage.status; + if (!status.isGranted) { + // Show explanation dialog first + if (mounted) { + final shouldOpen = await showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Storage Access Required'), + content: const Text( + 'Android 11+ requires "All files access" permission to save music files.\n\n' + 'Please enable "Allow access to manage all files" in the next screen.', + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + FilledButton( + onPressed: () => Navigator.pop(context, true), + child: const Text('Open Settings'), + ), + ], + ), + ); + + if (shouldOpen == true) { + status = await Permission.manageExternalStorage.request(); + } + } + } } else { + // Android 10 and below: Use legacy storage permission status = await Permission.storage.request(); }