Android下载进度

Tsi*_*mmi 23 android progress

我想知道一些下载的进度.
当我从互联网上获取一些资源时,像这样:

        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
        }
Run Code Online (Sandbox Code Playgroud)

当"InputStream in = httpConnection.getInputStream();"时 被调用,
文件的所有内容立即下载.

如果我使用:

        htttpResponse = httpClient.execute(httpRequestBase);
Run Code Online (Sandbox Code Playgroud)

问题是一样的.

如何检测下载的实际进度?

谢谢你们!

GaZ*_*GaZ 9

我想这已在这里得到解答.

简而言之:使用"Content-Length",它应该在标题字段中.

编辑:对不起,我没有完全回答这个问题.基本上,一旦您知道预期的总内容长度,您就可以跟踪您收到的数据量并计算完成百分比.

另请参阅:如何创建下载管理器