but how to validate if the app currently has the ‘All Files Access’ permission or not. i use this method to ask permission.
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",this.getPackageName())));
startActivityForResult(intent, 2296);
Please help me to fix this 🙁
3
Answers
create new dummy 0-bytes file in root of internal memory and then remove it. if both operations success then you have access. when you won’t have access then your code will
throw Exception
(on create-file step), which you cantry{ }catch(Exception e)
(preventing app crash)path for internal/external/shared can be obtained from
Environment
class, I would try at firstgetExternalStorageDirectory
declare this permission in your
manifest.xml
:for asking
MANAGE_EXTERNAL_STORAGE
:get your result in
onActivityResult
so, basically you can check permission is granted or not in Android11 like this;
I do it that way:
Seems there is a better way now though:
Environment.isExternalStorageManager()