Skip to content

Concerns about the FILES AND MEDIA PERMISSIONS on Android as a developer

I’m developing an app that saves data into a database, I’m trying to backup and restore that database which I am able to do, my issue is with the “ominous” permmission popup on API30+

Allow management of all files

Allow this app to access modify and delete files on your device…..

Allow this app to access, modify and delete files on the device or any connected storage devices? this app may access files without asking you.

I’m not trying to do any of these things, I just want permission to do the backup/restore thing

here’s my code for requesting permission:

    private void requestStoragePermissionExport(){
        if( (Build.VERSION.SDK_INT  >= 30 )){
            try {
                Intent intent = new Intent(Manifest.permission.MANAGE_EXTERNAL_STORAGE);
                startActivityForResult(intent, 2296);
            } catch (Exception e) {
                Intent intent = new Intent();
                startActivityForResult(intent, 2296);
            ActivityCompat.requestPermissions(this, new String[]{
                    Manifest.permission.WRITE_EXTERNAL_STORAGE}, BACKUP_CODE);

is there a better way to handle this?


Alright so, after a bit of research I found the best solution for myself is as follows:

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + File.separator + "foldername"

this doesn’t require permissions and works on below and above API 30