1

While I have no problem on past Android, on Android 13 (actually my Pixel 7) I get the following exception:

PlatformException (PlatformException(read_external_storage_denied, User did not allow reading external storage, null, null))

While running my code as follows:

  final result = await FilePicker.platform.pickFiles(
                                type: Platform.isAndroid
                                    ? FileType.any
                                    : FileType.custom,
                                allowedExtensions: Platform.isAndroid
                                    ? null
                                    : ['bin', 'nano']);

I guess something has changed to the permission system.

I added the following permission to the app/src/main/AndroidManifest.xml without success:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Any idea?

Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
  • To pick a file and read it one does not need a single permission on Android. What is Flutter messing around that you do? – blackapps Apr 24 '23 at 14:34

2 Answers2

2

Yes, there is an issue for storage with Android 13 and you can read the discussion here https://github.com/Baseflow/flutter-permission-handler/issues/907

And the last comment and this Comment contains solution.

As SdkVersion 33 is for android 13 , changing it to 31 (android 12) .

so, may be it changing to 31 works as backward compatibility.

defaultConfig {

    applicationId "com.example.example"
    minSdkVersion 28
    targetSdkVersion 31
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
}

for permission

 var status = await Permission.storage.status;
debugPrint("storage permission " + status.toString());
if (await Permission.storage.isDenied) {

  debugPrint("sorage permission ===" + status.toString());
 
  await Permission.storage.request();
} else {
  debugPrint("permission storage " + status.toString());
 // do something with storage like file picker
}
Rohan Jariwala
  • 1,564
  • 2
  • 7
  • 24
  • Thanks buddy. For a quick fix, I downgraded to supporting Android 12 (changing `targetSdkVersion flutter.targetSdkVersion` to `targetSdkVersion 31`) – Stéphane de Luca Apr 24 '23 at 14:05
  • Any solution if we want publish app to Google Play? As that requires targetting 33. – jasxir Jun 22 '23 at 07:25
0

The file_picker package version 4.5.1 has a known issue with requesting permission on Android 13. To fix this, you need to update the package version to 5.1.0 or later, as the developer has fixed this issue in the later versions.

Tousif Irshad
  • 37
  • 2
  • 12