fire borrower
fire borrower

Reputation: 1

Access to Android/data/"SOME APP FOLDER" on Android 11 api30

how can i access to /Android/data/"Target app" in Android R (11)?

private boolean isPermissionGranted(){
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R){
        // for Android 11
        return Environment.isExternalStorageManager();

    }else {
        int readExternalStoragePermission = ContextCompat.checkSelfPermission(this , Manifest.permission.READ_EXTERNAL_STORAGE);
        return readExternalStoragePermission == PackageManager.PERMISSION_GRANTED;

    }
}
public void takePermission(View view){
    if (isPermissionGranted()){
        Toast.makeText(getBaseContext(), "Permission is Already Granted!", Toast.LENGTH_SHORT).show();
    }else {
        takePermission();
    }
}

private void takePermission(){
    if (Build.VERSION.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 , 100);
        }catch (Exception exception){
            Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
            intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
            startActivityForResult(intent , 100);
        }
    }else {
        ActivityCompat.requestPermissions(this , new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},101);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 100){
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R){
            if (Environment.isExternalStorageManager()){
                Toast.makeText(getBaseContext(), "Permission Granted in Android 11 ", Toast.LENGTH_SHORT).show();
            }else {
                takePermission();
            }
        }
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (grantResults.length > 0){

        if (requestCode == 101){
            boolean readExternalStorage = grantResults[0] == PackageManager.PERMISSION_GRANTED;
            if (readExternalStorage){
                Toast.makeText(getBaseContext(), "Read Permission is Granted in Android 10 or below", Toast.LENGTH_SHORT).show();
            }else {
                takePermission();
            }
        }

    }
}

that is working to write every where. but when i want to write in /storage/emulated/0/Android/data/"Some App Folder" i got this error: 2021-08-27 17:46:09.803 23862-23862/com.itscaptive.frpsrcchanger E/Permission_LOG: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.tencent.ig/SrcVersion.ini: open failed: EACCES (Permission denied)

anyone can help me? :)

Upvotes: 0

Views: 1025

Answers (1)

tyczj
tyczj

Reputation: 74031

Android 11 you no longer can access data folder of other apps

https://developer.android.com/about/versions/11/privacy/storage#other-apps-data

Upvotes: 2

Related Questions