私はビデオをfirebaseにアップロードしています。シークバーと通知の両方で進行状況を表示したいと思います。私のシークバーが適切に動作しますが、進捗状況と私の通知は、シークバーが正常に動作しますが、進行に通知が時々ファイルがfirebaseにアップロードされていない場合でも、完全なダウンロードを示し、完全なダウンロードし表示した後、その進捗状況に通知の進捗状況を表示
@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);
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
final int progress = (int) ((100 * taskSnapshot.getBytesTransferred())/taskSnapshot.getTotalByteCount());
seekBar.setProgress(progress);
final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("Download in progress")
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
}
final NotificationManager notificationManager = (NotificationManager)
getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
new Thread(new Runnable() {
@Override
public void run() {
int incr;
// Do the "lengthy" operation 20 times
for (incr = progress; incr <= 100; incr++) {
// Sets the progress indicator to a max value, the
// current completion percentage, and "determinate"
// state
notificationBuilder.setProgress(100, incr, false);
// Displays the progress bar for the first time.
notificationManager.notify(id, notificationBuilder.build());
// Sleeps the thread, simulating an operation
// that takes time
try {
// Sleep for 5 seconds
Thread.sleep(5*1000);
} catch (InterruptedException e) {
Log.d(TAG, "sleep failure");
}
}
notificationBuilder.setContentText("Download complete")
// Removes the progress bar
.setProgress(0,0,false);
notificationManager.notify(id, notificationBuilder.build());
}
}
// Starts the thread by calling the run() method in its Runnable
).start();
}
});
}
}
をダウンロードを示し続けます私は間違って何をしているのですか?助けてください。私はすでに次のドキュメント&が進行して、私の通知が https://developer.android.com/training/notify-user/display-progress.html
ありがとう、私はあなたの助言に従った。あなたは大部分の権利を得た。私はdoInBackgoundにも通知コードを含めた。今すぐ稼働中の細かい – Pritish
@abuあなたは大歓迎です。 onCreate内でnotificationManagerとbuilderを初期化することもできます。このコードをdoInBackgroundに配置する必要はありません。 – Sahil