skip to Main Content

here is the permissions on my AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>

here is my build.gradle file

android {
    compileSdkVersion 34

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        applicationId "xxxxxxx"
        minSdkVersion 22
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
}

When I try to open the gallery, the app will open the app settings, but unfortunately I can’t find ‘Photo and videos’ permission at all to be allowed in ‘settings’ for Android 11 like the image below, I can only see ‘Files and Media’ permission which still I can’t open the photo gallery. I don’t have this issue on Android 13

enter image description here

I expect the app will open the gallery notification like this, instead of open the app settings
enter image description here

currently I am using Flutter and using Permission Handle Library and I use this code to ask permission to access the gallery

final status = await Permission.photos.request();

but it seems the status is always denied or permanentlyDenied so thats why I always open the app setting

  if (status == PermissionStatus.denied || status == PermissionStatus.permanentlyDenied) {
    openAppSettings();
    throw NoImageException("Photo gallery image permission is not granted");
  }

2

Answers


  1. Chosen as BEST ANSWER

    I can solve it using the code below, in you AndroidManifest.xml

            <!-- for below android 13-->
            <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
            
            <!-- for above android 13-->
            <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
       
    

    still in you AndroidManifest.xml add this one attribute on your application xml

    <application
            android:requestLegacyExternalStorage="true"
    </application>
    

    on your flutter (dart) I use the code below, I use Permission Handler and also Device Info Plus

          import 'package:device_info_plus/device_info_plus.dart';
          import 'package:permission_handler/permission_handler.dart';
    
          // check Android version used
          final DeviceInfoPlugin info = DeviceInfoPlugin();
          final AndroidDeviceInfo androidInfo = await info.androidInfo;
          final int androidVersion = int.parse(androidInfo.version.release);
    
          late PermissionStatus status;
    
          if (androidVersion >= 13) {
              status = await Permission.photos.request();
          } else {
              status = await Permission.storage.request();
          }
          
    
          if (status == PermissionStatus.denied || status == PermissionStatus.permanentlyDenied) {
            openAppSettings();
          }
    

  2. try exported true in mainefest and

    shrinkResources false
    minifyEnabled false

    in app section. build.gradle

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