如何使用内置的下载管理器在Android [英] How to use built-in download manager on Android

查看:162
本文介绍了如何使用内置的下载管理器在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发Android平台的应用程序,可以从我的服务器上下载一些文件。

I want to develop an application for the android platform that can download some files from my server.

我如何使用Android的下载管理器,像它采用的是Android市场的应用程序?我的意思是,一当用户下载的东西,下载状态显示在通知栏。

How can i use android's download manager like it is used in the Android market app? I mean, the one when the user downloads something, a download status is shown in the notification bar.

对不起我的英语!

推荐答案

你的意思大概是打造成为Android市场的应用程序的之一。所以我想有没有办法可以轻松地重新使用它,而是你必须建立一个类似自己。 你可能想看看下面的SO职位用于这一目的:

The one you mean is probably build into the Android market app. So I guess there is no way to easily reuse it but rather you'd have to build a similar one by yourself. You may want to check out the following SO posts for that purpose:

  • <一个href="http://stackoverflow.com/questions/2689729/progress-bar-in-notification-bar">http://stackoverflow.com/questions/2689729/progress-bar-in-notification-bar
  • <一个href="http://stackoverflow.com/questions/1871515/progress-bar-in-notification-bar-when-uploading-image">http://stackoverflow.com/questions/1871515/progress-bar-in-notification-bar-when-uploading-image
  • http://stackoverflow.com/questions/2689729/progress-bar-in-notification-bar
  • http://stackoverflow.com/questions/1871515/progress-bar-in-notification-bar-when-uploading-image

根据您使用什么样的文件,我发现从远程服务器下载文件的最简单方法是火象

Depending on what kind of files you use I found the easiest way to download files from a remote server is to fire an intent like

Intent downloadIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pathToFile));

如果在pathToFile是一个HTTP地址,例如PDF文档,浏览器会自动启动其显示在通知栏,一旦它完成下载,用户可以点击它,(根据的,如果应用程序安装)的文件将被打开。

If the "pathToFile" is an HTTP address to a pdf document for instance, the Browser will automatically start a download which is shown in the notification bar and once it is finished, the user can click on it and (if an according app is installed) the file will be opened.

如果您需要进一步从你的应用程序中处理下载的文件,那么它可能会更好自己处理的下载,打开HTTP连接等...

If you need to further process the downloaded files from within your app, then it's probably better to handle the download by yourself, opening an HTTP connection etc...

这篇关于如何使用内置的下载管理器在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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