Search code examples
androidflutterpermissionsfilepicker

FilePicker missing permission on Android 13 (Pixel 7)


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?


Solution

  • 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
    }