简体   繁体   中英

Saving files on sd card on android 11

I would like to save photos on the external app directory on the sd card on Android 11. What is the proper way to do this? Am I constrained to use SAF API with system picker triggered by action ACTION_OPEN_DOCUMENT_TREE where user have to select a folder on sd card?

Or maybe I can use this method:

File[] externalStorageVolumes =ContextCompat.getExternalFilesDirs(mContext, null);

and assume that if the sd card is available it will be on externalStorageVolumes[1] ? This worked on my 2 devices (Samsung j1 with android 5, and Samsung s10 with Android 10), but I don't have the opportunity to access more devices to test it.

On Android 11 (API level 30) and higher, apps cannot create their own app-specific directory on external storage .

Try Media storage api

Or target old android 10 and set requestLegacyExternalStorage=true in manifest

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