安卓:设置HttpURLConnection的速度极限 [英] Android: Set HttpUrlConnection speed limit

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

问题描述

是它可以设置下载速度限制在Android上HttpURLConnection的?

is it possible to set a download speed limit for a HttpUrlConnection in Android?

我的应用程序显示数据。数据被从Web服务器检索的。
有两种类型的数据被从Web服务器装在我的应用程序,以显示它们:
- 小文件(约1 MB)
- 大文件(大约100 MB)

My app displays data. The data is retrieved from a web server. There are two types of data that are loaded from the web server to display them in my app: - small files (about 1 MB) - big files (about 100 MB)

的问题是:
当我开始立即下载一个大文件,大约是100 MB,可能需要约5分钟,
我的应用程序是在此期间几乎unuseable。

The problem is: When I start to downlaod a big file, which is about 100 MB and may take about 5 minutes, my app is nearly unuseable in the meantime.

一个典型的情形是:
在一个大文件中的用户klicks - >大文件在后台下载。
在此期间用户要显示另一个小文件(1 MB,需时约几秒钟,从服务器加载它)。但问题是,与第一立即下载(装载大文件)使用整个带宽,因而小文件的下载时间约2分钟(而不是几秒)。

A typical scenario is: User klicks on a big file --> big file is downloaded in the background. In the meantime the User wants to display another little file (1 MB, should take about a few seconds to load it from server ). But the problem is, that the first downlaod (loading the big file) uses the whole bandwith and therefore the download of the small file takes about 2 minutes (instead of a few seconds).

所以,我想设置大文件speet限制(的带宽等例子一半),或实施一些优先级队列为下载...

So I would like to set a speet limit for big files (for example half of the bandwith etc.) or to implement some priority queue for downloads...

如何设定下载限制?

推荐答案

我会做的要么是使用下载管理器为previous评论者建议,如果你的API级别9+发展。麻烦的是这是一个下载在通知栏显示,你可能不希望这样。

What I would do is either use the DownloadManager as the previous commenter suggested, if you're developing for API level 9+. The trouble is with this is that downloads are shown in the notification bar and you might not want that.

据我可以看到有没有办法限制使用与Android使用HttpClient的一个特定的下载带宽。但我猜测你是下载使用每个文件中的AsyncTask的文件,AsyncTasks被串行执行,因此这可能解释为什么第二个文件没有开始下载。

As far as I can see there is no way to limit bandwidth on a specific download using the HttpClient used with Android. But I am guessing that you are downloading the file using an AsyncTask per file, and AsyncTasks are executed serially therefore that might explain why the 2nd file doesn't start downloading.

我强烈建议在 RoboSpice 寻找这是完美的这种类型的后台下载的。我是pretty相信你一定能够一次同时下载多个文件。

I strongly suggest looking at RoboSpice which is perfect for this type of background downloading. I'm pretty sure you will be able to download multiple files at once as well.

这篇关于安卓:设置HttpURLConnection的速度极限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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