'Android Scoped Storage Permission for Download Folder to Download PDF
I have an app that download specific pdf files using streamig Retrofit. I am upgrading my app targeting android 11. I have gone through many online documents and stackoverflow solutions and got it working. The files gets downloaded to Downloads folder.
With Scope Storage, do i need to ask for specific permission to read/write for 29 and above, as this folder is shared folder? I already have these in manifest.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
I am using this to check if permission is granted
public static boolean isPermissionGranted(Context context){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
return Environment.isExternalStorageManager();
} else {
int readExtStorage = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE);
int writeExtStorage = ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE);
return readExtStorage == PackageManager.PERMISSION_GRANTED && writeExtStorage == PackageManager.PERMISSION_GRANTED;
}
}
Do I need to use this also in manifest, and if so how do i handle if permission not granted?
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
I was thinking of using below, but i guess Playstore will reject my app with this absurd permission request.
Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
intent.addCategory("android.intent.category.DEFAULT");
Uri uri = Uri.fromParts("package",getPackageName(),null);
intent.setData(uri);
permissionActivityResultLauncher.launch(intent);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
