Displaying Progress In Notification
I am uploading a video to firebase and I want to show the status of the progress in both seekbar and in my notification. My seekbar behaves properly, but my notification with progr
Solution 1:
Your Thread code is the main problem. The loops iterate after every 5 seconds. Hence your answer for "it agains shows the notification of in progress." Remove the Thread from your code. It was just for example in Developer Guide
You can use AsyncTask
to do this. Code is as follow:
privateclassYourTaskLoaderextendsAsyncTask<Void, Void, Void> {
@OverrideprotectedvoidonPreExecute() {
super.onPreExecute();
notificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
builder = newNotificationCompat.Builder(this);
builder.setContentTitle("Picture upload")
.setContentText("Uploading in progress")
.setSmallIcon(R.drawable.ic_backup);
}
@OverrideprotectedVoiddoInBackground(Void... params) {
UploadPicture();
returnnull;
}
}
Call your AsyncTask
by following code when in need
new YourTaskLoader().execute();
and the code for onProgress()
method
In that loop
builder.setProgress(100,progress,false);
notificationManager.notify(1001,builder.build());
After the loop is over Call the following lines so that the progress in the notification bar is removed.
You can add these lines in onSuccess()
method.
builder.setContentText("Upload Complete")
.setProgress(0,0,false);
notificationManager.notify(1001,builder.build());
I hope it helps.
Post a Comment for "Displaying Progress In Notification"