Progress Bar % completed (download) Display in Android

后端 未结 3 1998
逝去的感伤
逝去的感伤 2020-12-21 15:28

I have a problem with Progress Bar showing % of download completed. I have a service class in which the downloading takes place. I can get the start time and end time of do

3条回答
  •  -上瘾入骨i
    2020-12-21 16:17

    Progress bar with counting %

    //you can use these method after Firebase Storage upload task

     final ProgressDialog progressDialog = new ProgressDialog(this);
       progressDialog.setTitle("Uploading...");
       progressDialog.show();
       progressDialog.setCanceledOnTouchOutside(false);
       StorageReference reference = storageReference
                                      .child("images/" + UUID.randomUUID().toString());
    
      reference.putFile(filePath).addOnProgressListener(new 
                                    OnProgressListener() {
                                    @Override
                                    public void onProgress(@NonNull UploadTask.TaskSnapshot 
                                          taskSnapshot) {
                                        double progress =                  
                 (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot.getTotalByteCount());
                                        progressDialog.setMessage("Uploaded "+ 
                                     (int)progress+"%");
    
                                    }
                                });
    

    Result

提交回复
热议问题