手动将本地文件添加到“下载"应用程序 [英] Manually add local file to the Downloads app
问题描述
我的应用程序需要下载文件,我正在研究DownloadManager,但是它有一些不适合我的情况的限制(身份验证,命名方案,验证),所以我制作了自定义下载引擎.
My app needs to download files, I was looking into DownloadManager, however it has some limitations that don't suit my case (authentication, naming scheme, verification), so I made my custom download engine.
是否可以手动将通过引擎下载的文件(因此使用本地URL)添加到下载"系统应用程序的列表中?我的理解是该列表由系统内容提供商填充.是否可以在没有DownloadManager尝试下载文件的情况下向其中添加记录?
Is it possible to manually add a file downloaded with my engine (thus by using a local URL) to the list in the Downloads system app? My understanding is that list is populated by a system content provider. Is it possible to add records to it, without the DownloadManager trying to download the file?
谢谢;)
推荐答案
要手动添加文件,您需要使用DownloadManager类.我使用以下内容在本地创建的下载"应用程序中显示文件.
To manually add a file you need to use the DownloadManager class. I use the following to show a file in the Download app 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);
即使文件是在本地创建的,这也会使该文件显示在6.0的下载"应用中.
This will make the file appear in the Downloads app on 6.0, even if the file was created locally.
这篇关于手动将本地文件添加到“下载"应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!