d.moncada d.moncada - 10 days ago 5
Android Question

Updating Android "Downloads" folder without using a DownloadManager

I'm currently running Marshmallow, and I have my application set up to download files into the phone's download folder by using the following path:

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)


and an
AsyncTask
. Everything works fine, I can access the files downloaded.

Though, the problem is that the files are only accessible on the phone using a File Browser, and not through the default
Downloads
folder via Android applications. I understand that you can do this automatically by using the Android
DownloadManager
, but I wanted to keep my current implementation of an
AsyncTask
without having to use
DownloadManager
.

My question is, is there a way I can simply "refresh" or "update" what is in the
Downloads
folder so they show up using the Android Downloads application?

I have also tried using the media scanner Intent (to refresh the gallery), but from my understanding, this does not work for Marshmellow.

activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));

Answer

is there a way I can simply "refresh" or "update" what is in the Downloads folder so they show up using the Android Downloads application?

The Downloads application only shows what is in its own ContentProvider, which in turn is driven by what was downloaded through DownloadManager. It is not showing the contents of any specific on-device directory, and that ContentProvider is not documented or supported for independent access.

I have also tried using the media scanner Intent (to refresh the gallery), but from my understanding, this does not work for Marshmellow.

That, or using MediaScannerConnection and scanFile(), will allow apps that query the MediaStore to see your file. This includes the MTP daemon; MTP is how a desktop OS views the contents of an Android device's external storage. None of that directly affects the Downloads app.

Comments