skip to Main Content

I’m developing a Flutter application where I need access to the user’s gallery (photos). I’m using the permission_handler package to request permissions. I’ve updated my AndroidManifest.xml to include the necessary permissions:

xml
Copy code
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/> However, when I try to request gallery permissions in Flutter using:

Permission.photos.request();
I encounter this error in my logs:

No permissions found in manifest for: []9
I/flutter (30483): permission result: PermissionStatus.denied

Has anyone come across this issue when trying to access the gallery on Android 13+ using Flutter? How can I ensure permissions are correctly requested and granted for gallery images across different Android versions?

Given that READ_MEDIA_IMAGES should be the right permission for accessing photos on newer Android versions, I’m puzzled as to why I’m facing this denial.

2

Answers


  1. You need add these permission for android 13 in the android manifest file

    <!-- Permissions options for the `storage` group -->
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <!-- Read storage permission for Android 12 and lower -->
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        <!--
          Granular media permissions for Android 13 and newer.
          See https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions
          for more information.
        -->
        <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
        <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
        <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    

    For more info and documentation
    https://pub.dev/packages/permission_handler

    Login or Signup to reply.
  2. Manifest file source code:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    

    Dart file source code:

      Future<bool> permissionPhotoOrStorage() async {
        bool perm = false;
        if (Platform.isIOS) {
          perm = await permissionPhotos();
        } else if (Platform.isAndroid) {
          final AndroidDeviceInfo android = await DeviceInfoPlugin().androidInfo;
          final int sdkInt = android.version.sdkInt ?? 0;
          perm = sdkInt > 32 ? await permissionPhotos() : await permissionStorage();
        } else {}
        return Future<bool>.value(perm);
      }
    
      Future<bool> permissionPhotos() async {
        bool hasPhotosPermission = false;
        final PermissionStatus try0 = await Permission.photos.status;
        if (try0 == PermissionStatus.granted) {
          hasPhotosPermission = true;
        } else {
          final PermissionStatus try1 = await Permission.photos.request();
          if (try1 == PermissionStatus.granted) {
            hasPhotosPermission = true;
          } else {}
        }
        return Future<bool>.value(hasPhotosPermission);
      }
    
      Future<bool> permissionStorage() async {
        bool hasStoragePermission = false;
        final PermissionStatus try0 = await Permission.storage.status;
        if (try0 == PermissionStatus.granted) {
          hasStoragePermission = true;
        } else {
          final PermissionStatus try1 = await Permission.storage.request();
          if (try1 == PermissionStatus.granted) {
            hasStoragePermission = true;
          } else {}
        }
        return Future<bool>.value(hasStoragePermission);
      }
      
    

    Dependent package: device_info_plus

    I also want to pick the document in one project. So, I wrote this code. I tested code from SDK 29 to SDK 34 & it is working incredibly. Give it a try. All you need to call is the permissionPhotoOrStorage() function.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search