0

I'm developing an app that can download some media files to the user selected folder (User selects folder using the SAF), targeting android 11+. It can download and create files on primary external shared storage (e.g. path: /storage/emulated/0/Download/) just fine. But when user selects a folder on the removable microSD card (e.g. path: /storage/XXXX-XXXX/Documents/) creating of files finishes with error (Cannot create file: /storage/9016-4EF8/...). Probably the reason of this error is denied permissions. I found tons of articles about android storage and came to the conclusion that apps can't create files at any folder on microSD card except the internal storage of the app on that sd card.

Summarising all above:

I can create files here:

path = "/storage/emulated/0/Download/" // primary external shared storage
path = "/storage/emulated/0/Android/data/com.app.app/files" // primary internal storage
path = "/storage/XXXX-XXXX/Android/data/com.app.app/files" // secondary internal storage on removabled microSD

I can't create files here:

path = "/storage/XXXX-XXXX/Download/" // secondary external shared storage

Since android 11+ internal storage of my app is no longer accesible from other apps. So for example picture downloaded using my app to the app folder can not be opened through any ImageEditor or Gallery. So the only way to correctly store files is to choose primary external shared storage.

The question is that some users has an external storage with max 2GB in size, they just need to download files to a microSD card. Is there any way to do it or is Android really such a dumb platform?

P.S. I am developing the app using QT C++, so files are created using standard C++ functions.

P.S.S. Sorry for my english

RomaFUN
  • 49
  • 6
  • If the user selects a folder you will not get such a path but a content scheme. What did you do that you did not tell is? – blackapps Oct 24 '22 at 19:13
  • @blackapps I used the code similar to one in this answer: https://stackoverflow.com/a/29789495/14792541 In outline there is a function that converts uri to real path. For example content://com.android.externalstorage.documents/tree/9016-4EF8%3AMovies/document/9016-4EF8%3AMovies becomes /storage/9016-4EF8/Movies – RomaFUN Oct 24 '22 at 19:25
  • Do not try to get a 'real path' from an uri as even if you manage to get one you have no write access using that path to a removable micro sd card since Android Kitkat. Exept for that ../Android/.. path. – blackapps Oct 24 '22 at 19:28
  • @blackapps I guess I can't do anything with that content schema in c++. Is there any way to get the path correctly or pass the schema to c++ file creation func? – RomaFUN Oct 24 '22 at 19:36
  • I wonder why that would not be possible. You use SAF and get a content scheme uri for a directory. How to continue i only know for Java, sorry. If you could manage for MANAGE_EXTERNAL_STORAGE you could use your path. – blackapps Oct 24 '22 at 19:52
  • @blackapps I think I can try use that permission. If my app targets 30 sdk, i guess it will work fine on android 11+, but what about previous versions? I guess 9th or 10th androids doesn't have MANAGE_EXTERNAL_STORAGE and saving on sd card will not work there. Am i right? Or will it work everywhere? – RomaFUN Oct 24 '22 at 20:04
  • No, as said before, since Kitkat not. But with the MANAGE_EXTERNAL_STORAGE again. So not on Q-. And for play store you better not use it. – blackapps Oct 24 '22 at 20:06

0 Answers0