update progress bar with Firebase uploading

18,049

Change the grouping of terms in your calculation of progress to force conversion to float. As your code is now, you are dividing two longs. The result of the division will be 0 until getBytesTransferred() == getTotalByteCount(), then it will be 1.

 double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
Share:
18,049
APP Bird
Author by

APP Bird

Updated on June 08, 2022

Comments

  • APP Bird
    APP Bird about 2 years

    I tried to add a progress bar to uploading files on firebase. but unfortunalty it does not indicate upload progress. both logcat & progress bar only indicate when file reached to 100%

       uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                    double progress = 100.0 * (taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount());
                    System.out.println("Upload is " + progress + "% done");
                int currentprogress = (int) progress;
                    progressBar.setProgress(currentprogress);
                }
            }).addOnPausedListener(new OnPausedListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onPaused(UploadTask.TaskSnapshot taskSnapshot) {
                    System.out.println("Upload is paused");
                }
            });
    
  • Frank van Puffelen
    Frank van Puffelen almost 8 years
    Ouch... that's a silly mistake in the code sample. I've made a note to fix it.
  • Chintan Soni
    Chintan Soni almost 8 years
    @FrankvanPuffelen Sir I have already reported the issue at code.google.com/p/android/issues/detail?id=215428
  • coderpc
    coderpc about 7 years
    is the style of progress bar horizontal ?
  • Bob Snyder
    Bob Snyder about 5 years
    @nivla360 Post your code and error output as a new question
  • gulab patel
    gulab patel almost 3 years
    I have did the same but still not getting updates. not even console. have any idea what can be wrong..., same code as above