0

It seems that getExternalStoragePublicDirectory() is now deprecated, so I need an alternative.

Say I have file the foo.png in my app's internal storage. I can easily access this file with

val foo = File(context.filesDir, "foo.png")

My problem is that I want to move this file to the user's Downloads directory, so that they can see it on their phone.

This answer uses DownloadManager. Unfortunately this is an image I generate myself, not download from somewhere.

cris
  • 99
  • 8
  • For an Android 20 device: Add android:requestLegacyExternalStorage="true" to application tag in manifest file and you can copy your file to that external storage location in the old way. After that delete original. – blackapps Sep 02 '20 at 07:30
  • Thank you, but I'm aware of that. It seems that is only a temporary solution. I'm looking for the long term solution. – cris Sep 02 '20 at 15:44
  • Then why didnt you say so? – blackapps Sep 02 '20 at 15:50
  • This was actually answered by user Frank in [here](https://stackoverflow.com/a/57940502/11848486). – cris Sep 03 '20 at 00:33

1 Answers1

1

You have two options.

Use Storage Acces Framework to let the user choose the Download directory .

Use MediaStore to insert file to Download directory.

blackapps
  • 8,011
  • 2
  • 11
  • 25