9

I am building an application in android where users can download remote files and save them to the external storage downloads directory. It works well and I am able to view files through Es File Explorer and other file explorer tools. But those files are not appearing in Downloads App in my Nexus 4 device. Please note that I am not using DownloadManager, instead I am creating HttpUrlConnection to remote server and downloading files.

Can anybody please tell me how to make the downloaded files appear in Downloads App without using DownloadManager?

Vivek
  • 1,823
  • 1
  • 19
  • 39

3 Answers3

13

You have to use DownloadManager to make the files show up in the app, but that doesn't mean you have to download them with DownloadManager. From API 12 onwards you can call DownloadManager.addCompletedDownload to add a file you've already downloaded to the downloads ContentProvider and therefore also to the GUI.

Dan Hulme
  • 14,779
  • 3
  • 46
  • 95
  • This works perfect as well after creating a file in the DIRECTORY_DOWNLOADS folder and even gives you a confirmation notification for free. In case you don't want the notification (false as last param of addCompletedDownload) a permission is needed, see http://stackoverflow.com/a/9374821/414581 – sunadorer Nov 27 '14 at 22:36
  • @Dan Hulme, can you please provide some source code how we can use this addCompletedDownload method, because it does not seem to work with me. – akash89 Feb 26 '16 at 11:07
  • This. This answer is awesome. – praneetloke Apr 25 '16 at 01:23
0

March 8th, 2017: A bit late to the party but this issue is still present. Check out the issue here.

I also found the solution from this comment. Call this when you finish downloading:

MediaScannerConnection.scanFile(
        this,
        new String[]{ file.getAbsolutePath() }, // "file" was created with "new File(...)"
        null,
        null);

One side note: One could argue that we'd better use DownloadManger. Yes but it is not always available.

Hoa Vu
  • 2,865
  • 4
  • 25
  • 33
-3

Maybe you should use the Downlaod App.

Don't know if this will help: https://support.mozilla.org/en-US/questions/950273

Set
  • 1
  • 2
    Probably not going to help the OP, as he is trying to build his own app to do the downloads. He is trying to figure out why another app on his device does not recognize the downloaded files. Also, try to refrain from off-site links as much as possible, as they can become invalid at some point. – bgse Jan 31 '14 at 23:14