App removed from google play store because of MANAGE_EXTERNAL_STORAGE

38 Views Asked by At

I have an app which is supposed to download facebook video and as android 11+ there were more restrictions on accessing user device folders , in my code i gave access to MANAGE_EXTERNAL_STORAGE but Google play store rejected my app for this reason . they required me to use MediaStore Api but i guess this api is only for reading and not writing files into , please what alternatives can be used to replace MANAGE_EXTERNAL_STORAGE , Thank you in advance .

enter image description here

This is code i'm using to grant MANAGE_EXTERNAL_STORAGE


Android 11

If you are targeting Android 11 (targetSdkVersion 30) then you require the following permissions in AndroidManifest.xml for modifying and document access.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
For Android 10 you place the following line in your AndroidManifest.xml tag

android:requestLegacyExternalStorage="true"
the method below checks if the permission is allowed or denied

private boolean checkPermission() {
   if (SDK_INT >= Build.VERSION_CODES.R) {
       return Environment.isExternalStorageManager();
   } else {
       int result = ContextCompat.checkSelfPermission(PermissionActivity.this, READ_EXTERNAL_STORAGE);
       int result1 = ContextCompat.checkSelfPermission(PermissionActivity.this, WRITE_EXTERNAL_STORAGE);
       return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED;
   }
}

private void requestPermission() {
   if (SDK_INT >= Build.VERSION_CODES.R) {
       try {
           Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
           intent.addCategory("android.intent.category.DEFAULT");
           intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName())));
           startActivityForResult(intent, 2296);
       } catch (Exception e) {
           Intent intent = new Intent();
           intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
           startActivityForResult(intent, 2296);
       }
   } else {
       //below android 11
       ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
   }
}


0

There are 0 best solutions below