简体   繁体   中英

How to save images in storage for all android versions and devices

I need to save images in storage from my android application, my code is working but not for all devices and android versions.

i need some solution or code from you that can save my images in all device and android versions.

i need to store data into android folder for my application privacy. i'm wanna to use storage like whatsapp. whatsapp can store images, videos, document all is in storage/emulated/0/Android/media/ without spacial permission and access easily, so what can i do, how can i manage it.

but i got issue with some samsung device. to store images in file manager

NOTE: I need to save images in all type android version like [Android version 8, 9, 10, 11, 12, etc...] and any device like, [MI, Samsung, Oneplus, etc....]

For all versions you can store to: storage/emulated/0/Android/data/APP_PACKAGE/.

Or in general to getExternalFilesDir() .

Also for all versions you can store to:

File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)
       , "MyFolder");

Update: getExternalFilesDir is not private on Android Q-;

For an app private storage location for all versions use getFilesDir() .

For media use getExternalMediaDirs() available since Lollipop but not private on Q- And not private on higher versions for apps with MANAGE_EXTERNAL_STORAGE. And never for file manager apps.

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