手动将本地文件添加到下载应用程序 [英] Manually add local file to the Downloads app

查看:37
本文介绍了手动将本地文件添加到下载应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要下载文件,我正在查看 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)手动添加到下载"系统应用程序的列表中?我的理解是该列表由系统内容提供者填充.是否可以在不下载管理器尝试下载文件的情况下向其中添加记录?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆