安卓:编程方式使用浏览器下载文件 [英] Android: download file programatically using the browser

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

问题描述

我的应用程序有一个包含文件网址,通常类似于一个Word文档或PDF文件中的字符串。我想给用户一个方法来下载文件的方式他们,如果他们点击了浏览器的链接(让浏览器存储在默认位置等)上。

My app has a string containing the URL to a file, typically something like a Word document or a PDF file. I want to give the user a way to download the file the same way they would if they had clicked on a link in the browser (letting the browser store it in the default location, etc).

目前,我被发动ACTION_VIEW意图这样做。它在大多数情况下,但也有几个问题它。常浏览器窗口尝试显示的消息由于某种原因立即消失并且不能被读出。有时,下载失败,我无法检测到。如果成功,真正看到所有的用户是他们必须知道要寻找的顶部状态栏上的小图标。

At the moment I am doing this by launching an ACTION_VIEW intent. It works in most cases, but there are several problems with it. Often the browser window tries to display a message which for some reason immediately disappears and can't be read. Sometimes the download fails and I can't detect that. If it does succeed, all the user really sees is a small icon in the top status bar that they have to know to look for.

有没有更好的方法来做到这一点?一些方法来启动一个专门的下载行为,而不是调用整个浏览器的?

Is there a better way to do this? Some way to start a dedicated DOWNLOAD action instead of invoking the whole browser?

莫非我下载的文件我在我自己的code和然后以某种方式导致它在同一个地方结束,如果浏览器已经下载了吗?

Could I download the file myself in my own code and then somehow cause it to end up in the same place as if the browser had downloaded it?

感谢。

推荐答案

您可以用自己的code下载它,并把它在的 \\ Download文件夹在SD卡上。或者,您可以使用 下载管理器 的API 9及更高版本。

You can download it with your own code, and place it in the \Download folder on the SD card. Alternatively, you could use the DownloadManager available on API 9 and above.

这篇关于安卓:编程方式使用浏览器下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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