简体   繁体   中英

clearing ongoing notification in android

In my application iam showing a ongoing notification while doing a video upload. I want to clear the notification after upload. I searched a lot and cant get a clear answer.Please help me if anybody knows...

From Managing your Notifications in android documentation:

You can also clear it manually with cancel(int), passing it the notification ID, or clear all your notifications with cancelAll().

So you should perform following to hide the notification:

mNotificationManager.cancel(notification_id);

where mNotificationManager is NotificationManager object and notification_id is int identifier of notification passed to NotificationManager object:

mNotificationManager.notify(notification_id, notification);

Just to show how this is done with Notification.Builder you can set the FLAG_AUTO_CANCEL like this:

Notification.Builder mBuilder = new Notification.Builder(getContext())
                    .setSmallIcon(R.drawable.icon)
                    .setContentTitle("My notification")
                    .setContentText("Hello Notify!")
                    .setOngoing(true)
                    .setAutoCancel(true);

You can clear your notification by clicking on it..!!

Notification notification = new Notification("Your needed data..");

notification.flags |= Notification.FLAG_AUTO_CANCEL;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM