Skip to content

How to get progress (percent) when downloading image from url #75

Open
@0xcra5hs

Description

@0xcra5hs

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions