Open
Description
How to get progress (percent) when downloading image from url .
I think i should customize code at HttpUrlDownloader.java
Here it's what i'm going so far ::
while (true) {
final URL u = new URL(thisUrl);
urlConnection = (HttpURLConnection) u.openConnection();
urlConnection.setInstanceFollowRedirects(true);
if (mRequestPropertiesCallback != null) {
final ArrayList<NameValuePair> props = mRequestPropertiesCallback.getHeadersForRequest(context, url);
if (props != null) {
for (final NameValuePair pair : props) {
urlConnection.addRequestProperty(pair.getName(), pair.getValue());
}
}
}
if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_MOVED_TEMP
&& urlConnection.getResponseCode() != HttpURLConnection.HTTP_MOVED_PERM)
break;
thisUrl = urlConnection.getHeaderField("Location");
}
if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
UrlImageViewHelper.clog("Response Code: " + urlConnection.getResponseCode());
return null;
}
is = urlConnection.getInputStream();
//customize
int fileLength = urlConnection.getContentLength();
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = is.read(data)) != -1) {
total += count;
publishProgress((int) (total * 100 / fileLength));
}
callback.onDownloadComplete(HttpUrlDownloader.this, is, null);
return null;
I can get progress by publishProgress , but when progress = 100% then ImageView not show
Sorry , My English is bad :( .Help me !!
Metadata
Metadata
Assignees
Labels
No labels