0

I am using Download Manager in android to download images and Videos from a particular Url.

So, When Downloading is in Progress, I am displaying a simple Progressbar.

Instead, I wanna to display custom Progressbar, which display the progress of content downloaded. That means It should display a view so that User can know that How much data is downloaded.

Just like WhatsApp is doing with downloading images and videos.

Thanks.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
jaimin
  • 23
  • 1
  • 8
  • Please google before posting a new Question on SO. Kindly go through [this](https://stackoverflow.com/questions/15795872/show-download-progress-inside-activity-using-downloadmanager) post – NightFury Mar 12 '18 at 07:51

1 Answers1

0

used below code to show percentages download is complete like below ...

<ProgressBar
    android:id="@+id/xml_reg_progressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/common_left_right_margin"
    android:layout_marginRight="@dimen/common_left_right_margin"
    android:layout_marginTop="@dimen/reg_ph_linear_top_margin"
    />

and used below code to show it...

protected static final int TIMER_RUNTIME = 180000; // in ms --> 10s
private ProgressBar progressTimer;
public void startTimer() {
        final Thread timerThread = new Thread() {
            @Override
            public void run() {
                mbActive = true;
                try {
                    int waited = 0;
                    while (mbActive && (waited < TIMER_RUNTIME)) {
                        sleep(1000);
                        if (mbActive) {
                            waited += 1000;

                            updateProgress(waited);
                        }
                    }
                } catch (InterruptedException e) {
                    // do nothing
                } finally {
                    onContinue();
                }
            }

        };
        timerThread.start();

    }

    Handler handler = new Handler();

    private void onContinue() {
        handler.post(new Runnable() {
            @Override
            public void run() {

                txtCallContactUsNumber
                        .setText(CommonVariable.CallForSupporMessage
                                + contactInfo.MobileNo);

            }
        });

    }

    public void updateProgress(final int timePassed) {
        if (null != progressTimer) {
            // Ignore rounding error here
            final int progress = progressTimer.getMax() * timePassed
                    / TIMER_RUNTIME;
            handler.post(new Runnable() {
                @Override
                public void run() {
                    Log.i("timePassed", "timePassed=" + timePassed);

                    DateFormat formatter = new SimpleDateFormat("mm:ss");
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTimeInMillis(timePassed);
                    String timer = formatter.format(calendar.getTime());
                    formatter.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
                    txtTimerCount.setText(formatter.format(timePassed));
                }
            });

            progressTimer.setProgress(progress);
        }
    }

in my above code this will call 1 second and get progress increment every 1 second.