Isa*_*ler 33 browser url android download android-intent
我想知道下载URL的意图是什么?在浏览器中,它会下载带有一点通知图标的东西.我想知道我是否可以使用这个意图(以及它是什么).
Ale*_*min 69
应用程序可以使用下载管理器下载文件,就像浏览器和Gmail一样.这是从姜饼开始.
您的应用需要INTERNET权限才能启动下载.要将文件保存在默认的下载目录中,还需要WRITE_EXTERNAL_STORAGE权限.
以下是您可以下载URI的方法:
DownloadManager.Request r = new DownloadManager.Request(uri);
// This put the download in the same Download dir the browser uses
r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "fileName");
// When downloading music and videos they will be listed in the player
// (Seems to be available since Honeycomb only)
r.allowScanningByMediaScanner();
// Notify user when download is completed
// (Seems to be available since Honeycomb only)
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
// Start download
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(r);
Run Code Online (Sandbox Code Playgroud)
还有许多其他选项可用于自定义通知,查询下载状态和设置下载位置.
此博客文章介绍了如何通过隐藏API在以前版本的Android上使用下载管理器.
dpa*_*nas 18
虽然我不相信浏览器中有下载Intent,但您可以使用普通的ACTION_VIEWIntent并让浏览器决定是否应该根据内容类型下载或查看URL.
所以从你的代码触发器
new Intent(Intent.ACTION_VIEW, Uri.parse(url))
Run Code Online (Sandbox Code Playgroud)
并希望这会在浏览器中触发下载.