Handling Scope Storage for Android 11 and above
Opened this issue · 3 comments
Will this lib be further developed so that it also works with Android 11, where the authorization concept is completely different?
Will this lib be further developed so that it also works with Android 11, where the authorization concept is completely different?
I also use this lib, but the permissions don't work on smartphones with Android 11 and higher.
Hi, PR with updates are welcomed and highly encouraged.
I didn't test this library for all cases on Android 11
Also can you specify what is not working in more details?
We use the following method of your lib. That works/worked until Android 10. From Android 11, as mentioned, has a different concept of accessing/writing files. Therefore the app cannot access to /storage/emulated/0/ to make there an directory and under there a zip-file like /storage/emulated/0/myDir/file.zip.
Error message "Permission denied". On other devices with Android < 11, it works!
It would be great if the library would be expanded accordingly so that it corresponds to Android's authorization concept.
public static Boolean askForReadPermission(final Activity activity, final PermissionCallback permissionCallback, View view){
if(android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Nammu.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)){
return true;
}
else{
final String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
if (Nammu.shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)){
Snackbar.make(view, activity.getString(R.string.error_permission_backup),
Snackbar.LENGTH_INDEFINITE)
.setAction("OK", new View.OnClickListener() {
@Override
public void onClick(View view) {
Nammu.askForPermission(activity, permissions, permissionCallback);
}
}).show();
} else {
Nammu.askForPermission(activity, permissions, permissionCallback);
}
return false;
}
}
I believe with Scope Storage it is up to app developer to pick either a particular file from external storage or ask for "All file access" (however it shouldn't be assumed as default behavior as a replacement for WRITE_EXTERNAL_STORAGE
).
I tried this on Android 13 and seems to be working as intended in existing functionality (it returns "permission refused").
If you believe this should be part of this library for every app - please provide a PR with a change.