2017-08-24 58 views
0
floatingActionButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
       intent.setType("video/*"); 
       intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); 
       startActivityForResult(Intent.createChooser(intent, "Complete action using"), RC_PHOTO_PICKER); 

      } 
     }); 

@Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) { 
      Uri selectedImageUri = data.getData(); 

      // Get a reference to store file at chat_photos/<FILENAME> 
      StorageReference photoRef = mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment()); 

      // Upload file to Firebase Storage 
      photoRef.putFile(selectedImageUri) 
        .addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() { 
         public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 
          // When the image has successfully uploaded, we get its download URL 
          // progressBar.setVisibility(View.VISIBLE); 
          Uri downloadUrl = taskSnapshot.getDownloadUrl(); 

          // Set the download URL to the message box, so that the user can send it to the database 
          Video video = new Video(downloadUrl.toString()); 
          mMessagesDatabaseReference.push().setValue(video); 
         } 
        }); 
     } 
    } 

我想在圖像上傳爲通知時在seekbar上顯示進度。我怎麼做?我在onCreate中創建了一個Seekbar對象。如何獲取我上傳的視頻的持續時間,並在通知中顯示搜索欄,並且用戶在上載開始時不應該能夠輕掃通知?請幫忙。當視頻上傳到android中的firebase時顯示seekbar

+0

退房這個問題的【答案】(https://stackoverflow.com/questions/37457152/how-to-show-progress-bar-status -by-percentage-while-uploading-json-data) – karthik

回答

1

你可以通過使用addOnProgressListener

.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() { 
     @Override 
     public void onProgress(UploadTask.TaskSnapshot taskSnapshot) { 
      int progress = (int) ((100 * taskSnapshot.getBytesTransferred())/taskSnapshot.getTotalByteCount()); 
      try { 
       yourSeekBar.setProgress(progress); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    }) 
+0

老兄,你是上帝。非常感謝你。 – Pritish

+0

你能幫我解決嗎? https://stackoverflow.com/questions/45862094/displaying-progress-in-notification – Pritish