简体   繁体   中英

Create directory without manage all files permission

Hello 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM