Skip to content
Advertisement

Create directory without manage all files permission

How can i create directory in ( /storage/emulated/0/ ) without manage all files permission. This is my code :

        File myFolder=new File(Environment.getExternalStorageDirectory(),"testDir");
        if(!myFolder.exists() || myFolder.isFile()){
            if(myFolder.isFile()){
                Toast.makeText(getApplicationContext(), "'testDir' exists as file", Toast.LENGTH_LONG).show();
                return;
            }
            try{
                myFolder.mkdir();
                Toast.makeText(getApplicationContext(), "Directories created successfully", Toast.LENGTH_SHORT).show();
            } catch(Exception e){
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }


        }

On android 11 its not working because it need manage all files permission.

Advertisement

Answer

From SDK 30 you can not access all file system without using MANAGE_EXTERNAL_STORAGE.

If your app is in following categories you can ask for this permission:

  • File management
  • Backup and restore apps
  • Anti-virus apps
  • Document management apps
  • Search (On Device)
  • Disk/Folder Encryption and Locking
  • Device Migration/Phone transfer

ref: https://support.google.com/googleplay/android-developer/answer/10467955?hl=en#zippy=%2Cpermitted-uses-of-the-all-files-access-permission

If your app is photo, video editing app or something like this than in that case you don’t need this permission. You can simply use SAF or media directory like DCIM, Downloads, Videos etc…and create your folder there to save your images, videos etc. other way, you can use Android/ media or data folder.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement