下载一个大文件在android系统的最佳方式? [英] The best way to download a big file in android?

查看:191
本文介绍了下载一个大文件在android系统的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要下载我的应用程序(几乎2GB)大的文件,我想知道什么是做的最好的方法,有些库,来帮助我。
首先,我看了 Android的异步HTTP库,但我没有找到例子,说明如何发布进度或开始,暂停下载。然后,我不知道我是否应该使用这个lib或只使用一个非标准的HTTP公地。
另一个问题是,我应该使用<一个href=\"http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog/3028660#3028660\">service下载我的档案?

I need to download a big file on my app (almost 2gb) and i was wondering what is the best way to do that and some libs to help me. First I looked the Android Asynchronous Http Library but I didn't find examples showing how to publish the progress or start, pause download. Then I don't know if should I use this lib or just use a standart http commons. Other problem is, should I use a service to download my file??

难道你们给一个提示,那怎么办?

Could you guys give a hint, how to do that?

推荐答案

我已经看到你有一堆答案,没有人真的回答它从一个整体的角度。

I've see you got a bunch of answer and none of them really answers it from a holistic point of view.

要下载一个2K的或2GB的文件中的实际code是相同的使用某种类型的连接处理器和一些类型的输入流和输出流,通常包装用缓冲输入流的输入流。对于您可以找到Java实例的无限量周围所有的网页。

To download a 2k or 2gb file the actual code is the same using some type of connection handler and some type of input stream and output stream and usually wrapping the input stream with a buffered input stream. For that you can find infinite amount of java examples all around the web.

在这里考虑Android平台的诀窍是因为它是一个冗长的操作,你不应该这样做活动的生命周期内都没有。

The trick here considering the Android platform is that because it's a lengthy operation, you shouldn't be doing it inside the activity life cycle at all.

说你有两种选择:


  • 如你所说,你可以创建一个服务,我会建议你使用的 IntentService
    因为它似乎是这种情况下,一个完美的结合。该IntentService自动跨越一个新的线程,通过意图传递URL作为一个字符串,并使用流等让服务下载。

  • as you suggested you can create a Service, I would suggest you to use the IntentService as it seems to be a perfect fit for this case. The IntentService automatically spans a new thread, through the intent you pass the URL as a String and let the service download using the streams, etc.

另一种方法,可能工作得很好,但我从来没有亲自使用,就是使用的下载管理可用自姜饼。它不应该是很难叫 getSystemService(Context.DOWNLOAD_SERVICE)并调用 dwManag.enqueue(dwRequest);

another method that probably work well, but I've never personally used, is to use the DownloadManager that is available since Gingerbread. It shouldn't be difficult to call getSystemService(Context.DOWNLOAD_SERVICE) and call dwManag.enqueue(dwRequest);

希望它帮助。

这篇关于下载一个大文件在android系统的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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