[Solved] FilePicker missing permission on Android 13 (Pixel 7) – Android

by
Ali Hasan
android android-permissions filepicker flutter

Quick Fix: For Android 13, the solution is to add the ACCESS_MEDIA_LOCATION permission to the manifest and target SDK version to 31.

The Problem:

While using the FilePicker package, the code fails to access external storage on Android 13 devices, throwing a ‘PlatformException: User did not allow reading external storage’ error despite having the ‘READ_EXTERNAL_STORAGE’ permission declared in the manifest.

The Solutions:

Solution 1: Changing targetSdkVersion to 31 (android 12)

As SdkVersion 33 is for android 13, changing it to 31 (android 12) in the `app/src/main/AndroidManifest.xml` may work as backward compatibility.

AndroidManifest.xml:

<manifest ...>
    <application ...>
        ...
        <defaultConfig ...>
            ...
            targetSdkVersion 31
            ...
        </defaultConfig>
        ...
    </application>
    ...
</manifest>

Solution 2: Requesting storage permission before using FilePicker

Request storage permission using the `flutter_permission_handler` package before using the `FilePicker`.

Example code:

import 'package:permission_handler/permission_handler.dart';

...

// Request storage permission
var status = await Permission.storage.status;
if (status.isDenied) {
  await Permission.storage.request();
}

// Use FilePicker after permission is granted
final result = await FilePicker.platform.pickFiles(...);

Solution 3: Update the file_picker Package

To resolve the permission issue on Android 13, you need to update the file_picker package to version 5.1.0 or later. This updated version includes a fix for the permission request issue on Android 13 devices.

Q&A

Is there an open issue related to this?

Yes, you can read the discussion here: https://github.com/Baseflow/flutter-permission-handler/issues/907.

What’s the quick solution for it?

Change your targetSdkVersion to 32.

Is the issue fixed in latest package releases?

Yes, the issue is fixed in file_picker package version 5.1.0 and later.

Video Explanation:

The following video, titled "How To Fix Android File Manager - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Let's show you how to fix Android's File Manager. In this video, I walk you through the steps to fix when the File Manager on your Android ...