安卓下载进度
我想知道某些下载的进度。
当我从互联网上获取一些资源时, 像这样:
String myFeed = request.getURI().toString();
URL url = new URL(myFeed);
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpConnection.getInputStream();
// Process the input stream
}
当“InputStream in = httpConnection.getInputStream();”时被称为,
文件的所有内容都会立即下载。
如果我使用:
htttpResponse = httpClient.execute(httpRequestBase);
问题是一样的。
如何检测下载的实际进度?
谢谢大家!
I want to know the progress of some download.
When I'm getting some resource from the internet,
like this:
String myFeed = request.getURI().toString();
URL url = new URL(myFeed);
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpConnection.getInputStream();
// Process the input stream
}
When "InputStream in = httpConnection.getInputStream();" is called,
all the content of the file is downloaded at once.
If I use:
htttpResponse = httpClient.execute(httpRequestBase);
The problem is the same.
How can I detect the actual progress of the download?
Thank you all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这已此处得到解答。
简而言之:使用应位于标头字段中的“内容长度”。
编辑:抱歉,我没有准确回答问题。基本上,一旦您知道预期的总内容长度,您就可以跟踪收到的数据量并计算完成的百分比。
另请参阅: 如何创建下载管理器
I think this has been answered here.
In a nutshell: use the "Content-Length" which should be in the header fields.
EDIT: sorry, I wasn't answering the question exactly. Basically once you know the expected total content length then you can keep track of how much data you have received and calculate the percentage complete.
See also: How to create a download manager