Home > OS >  android version 10 creating issue with manage external storage whereas the code is running fine with
android version 10 creating issue with manage external storage whereas the code is running fine with

Time:12-19

I am trying to download file. So in android 11 i need manage external storage permission. These permission i have given and they are working fine with android 11. downloading is happening and files are being stored. But when i work with android 10 then there is an error no permissions found in manifest for 22 which i searched over internet and found that this is the error for

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
    tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>



void getPermission() async {
var status = await Permission.storage.request();
var status3 = await Permission.manageExternalStorage.request();
if (status.isGranted && status3.isGranted) {
  // print('granted');
  //var status2 = await Permission.accessMediaLocation.request();
  //if (status2.isGranted) {
  setState(() {
    _allowWriteFile = true;
  });
} else {
  // print("denied");
}

}

CodePudding user response:

I'm having same issue I solve by doing this.For android 10 you have to give permission in mainActivity,

class MainActivity: FlutterActivity() {

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {

        GeneratedPluginRegistrant.registerWith(flutterEngine);

        if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.Q){
            setupPermissions()
        }
    }

    private fun setupPermissions() {


        if (ContextCompat.checkSelfPermission(this@MainActivity,
                android.Manifest.permission.WRITE_EXTERNAL_STORAGE) !==
            PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale(this@MainActivity,
                    android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                ActivityCompat.requestPermissions(this@MainActivity,
                    arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
            } else {
                ActivityCompat.requestPermissions(this@MainActivity,
                    arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
            }
        }
    }

CodePudding user response:

try adding the following in the android manifest file, inside application tag.

 <application
   android:requestLegacyExternalStorage="true" ...  </application>
  • Related