Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
0xcra5hs opened this issue Nov 24, 2013 · 0 comments
Open

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

0xcra5hs opened this issue Nov 24, 2013 · 0 comments

Comments

@0xcra5hs
Copy link

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 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant