9

This may be a stupid question, but I really need an answer to it.

As far as I understand, starting with Android 10, the recommended way is to save files to the internal directory of the application, which the system allocates for it.

In my application, users download content and then can (and most often do) delete it or import it into the game using the Uri scheme. When trying to save the file this way I can save the file and even delete it, but not import. Saving to cache is not suitable for my application. There are methods that depend on the presence of saved files on the device.

However, with the help of DownloadManager, I can save, delete and import files into the game from the Downloads directory.

Question: can I save files to the Download folder on Android 11 and higher, and if not, please tell me another way so as not to break any rules.

Thank you very much for your attention!

Lordix Games
  • 103
  • 1
  • 4
  • Theoretically you can use [ContentResolver.openOutputStream](https://developer.android.com/reference/android/content/ContentResolver#openOutputStream(android.net.Uri)) with `MediaStore.Downloads.EXTERNAL_CONTENT_URI` and write your files there. More info [here](https://developer.android.com/training/data-storage/shared/media). Never tested Downloads this way though – artman Feb 26 '21 at 07:40
  • `I can save the file and even delete it, but not import` Why not? I see no reason. – blackapps Feb 26 '21 at 08:01
  • `with the help of DownloadManager, I can save, delete and import files into the game from the Downloads directory.` Wel nice. But i do not understand. You say there is a file in Downloads and then DownloadManager can import it in the game? What is happening exactly then? And who put that file in Downloads and how? – blackapps Feb 26 '21 at 08:05
  • `can I save files to the Download folder on Android 11` Of course you can. Use DownloadManager. – blackapps Feb 26 '21 at 08:05
  • I do not understand that getFilesDir() is not usable. Or getExternalFilesDir(). Please explain. – blackapps Feb 26 '21 at 08:07
  • `and then can (and most often do) delete it or import it into the game using the Uri scheme` It is unclear where they got that uri from. – blackapps Feb 26 '21 at 08:13
  • @blackapps sorry for long answer. I have no idea why import is not working, because the `data` folder is now closed. I see that it changes when downloading and deleting the file, but when I try to import the file, nothing happens in the game. Previously, everything worked – Lordix Games Feb 26 '21 at 08:57
  • @blackapps Question: Wel nice. But i do not understand. You say there is a file in Downloads and then DownloadManager can import it in the game? What is happening exactly then? And who put that file in Downloads and how? Answer: No, DownloadManager only helps save file to the Download folder and then import happens via Uri scheme – Lordix Games Feb 26 '21 at 08:58
  • @blackapps >> Of course you can. Use DownloadManager. Thank you very much! I was worried that this might be prohibited, so I decided to clarify here, thanks again! – Lordix Games Feb 26 '21 at 09:01
  • @blackapps I do not understand that getFilesDir() is not usable. Or getExternalFilesDir(). Please explain. I tried both of them but and both of them working for downloads and delete but not for import, unfortunately. But if download files is allow for Android 11 then its good for me and i continue use DownloadManager for that, thank you :) – Lordix Games Feb 26 '21 at 09:03
  • @artman Thank you for the link, i will check it! – Lordix Games Feb 26 '21 at 09:05
  • `but not for import, unfortunately. ` You are explaining nothing. I asked you why you did not succeed. I see no reason. – blackapps Feb 26 '21 at 09:17
  • @blackapps `You are explaining nothing. I asked you why you did not succeed. I see no reason` and i answred to you that it works only for downloading and deleting, but in case of import via Uri nothing happens, no errors in logs. And i don't understand why it doesn't works and becuase of that i asked a question. The same code from Downloads folder works perfectly – Lordix Games Feb 26 '21 at 10:01
  • You should allready long ago have posted your code. You only say that 'it' does not work and you did not manage to make clear what was 'it'. – blackapps Feb 26 '21 at 10:19

0 Answers0