Android 11 access to Android/data folder

Viewed 289

In purpose to get storage permissions in Android 11 I have found here a nice code which works fine for me

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
        if(!Environment.isExternalStorageManager()){
            try {
                Uri uri = Uri.parse("package:" + BuildConfig.APPLICATION_ID);
                Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, uri);
                intent.addCategory("android.intent.category.DEFAULT");
                intent.setData(Uri.parse(String.format("package:%s", getApplicationContext().getPackageName())));
                startActivity(intent);
            } catch (Exception ex){
                Intent intent = new Intent();
                intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
                startActivity(intent);
            }
        }
    } else {
        if(ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
        }
    }

But Android 11 has more strict rules for access to the folders like ...Android/data/... There is an opinion, that indeed applications can not have access to Android/data/ content anymore. At the same time there are Files Explorers type of applications that can do it easily after getting an additional/special permision (see a snapshot below)

enter image description here

Could anyone help me how can I make same request for permission as shown on the snapshot above?

0 Answers
Related