安卓下载意图 [英] Android Download Intent

查看:31
本文介绍了安卓下载意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道下载 URL 的意图是什么?在浏览器中,它将下载带有小通知图标的内容.我想知道我是否可以使用该意图(以及它是什么).

I was wondering what is the intent for downloading URLs? In the browser, it will download stuff with a little notification icon. I was wondering if I can use that intent (and what it is).

推荐答案

应用程序可以像浏览器和 gmail 一样使用下载管理器下载文件.这从 Gingerbread 开始可用.

Applications can download files with the download manager just like the browser and gmail. This is available starting with Gingerbread.

您的应用需要 INTERNET 权限才能启动下载.要将文件保存在默认下载目录中,它还需要 WRITE_EXTERNAL_STORAGE 权限.

Your app needs the INTERNET permission to initiate a download. To save the file in the default Download directory it also needs the WRITE_EXTERNAL_STORAGE permission.

以下是下载 URI 的方法:

Here's how you can download an 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);

还有许多其他选项可用于自定义通知、查询下载状态和设置下载位置.

There are a bunch of other options for customizing the notification, querying the download state and setting the download location.

这篇博文展示了如何在以前版本的 Android 上使用下载管理器通过隐藏的 API.

This blog post shows how you could use the download manager on previous versions of Android via hidden APIs.

这篇关于安卓下载意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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