Manually add the local file to the Downloads application.

My application should download files, I was looking for DownloadManager, however it has some limitations that are not suitable for my business (authentication, naming scheme, verification), so I made my own loading mechanism.

Is it possible to manually add the file downloaded with my engine (in this way using the local URL) to the list in the "Download System" application? I understand that this list is populated by the system content provider. Can I add entries to it without downloading the DownloadManager to download the file?

Thanks;)

+6
source share
1 answer

To manually add a file, you need to use the DownloadManager class. I use the following to show the file in the Download application that I created locally.

DownloadManager downloadManager = (DownloadManager)mainActivity.getSystemService(mainActivity.DOWNLOAD_SERVICE); downloadManager.addCompletedDownload(file.getName(), file.getName(), true, "application/json", file.getAbsolutePath(),file.length(),true); 

This will cause the file to appear in the Download application on 6.0, even if the file was created locally.

+2
source

Source: https://habr.com/ru/post/945848/


All Articles