Write a notification notification tool class, which contains the listener system to clear the notification bar method, focus on bold italic part:
public class Notifier {
private static final String TAG = Notifier.class.getSimpleName ();
private static Notifier instance;
Private Context Mcontext;
private static final int notification_id_1 = 0;
private static final int notification_id_2 = 1;
private static final int notification_id_3 = 2;
private static final int notification_id_4 = 3;
private static final int notification_id_5 = 4;
private static final int notification_id_6 = 5;
private static final int notification_id_7 = 6;
private static final int notification_id_8 = 7;
public static Notifier getinstance (context context) {
if (instance = = null) {
Instance = new Notifier (context);
}
return instance;
}
Public Notifier (Context context) {
Mcontext = context;
}
Public Notificationmanager Getnotificationmanager (context context) {
Return (Notificationmanager) context
. Getsystemservice (Context.notification_service);
}
public void shownotify (context context, int largeicon, int smallicon,
Charsequence Tickertext, Charsequence ContentInfo,
Charsequence Contenttitle, charsequence contenttext) {
Pendingintent contentintent = pendingintent.getactivity (context, 0,
New Intent (context, Mainactivity.class), 0);
Bitmap Bitmap = Bitmapfactory.decoderesource (Context.getresources (),
LargeIcon);
Notificationcompat.builder Notifybuilder = new Notificationcompat.builder (
context);
Notifybuilder.setlargeicon (bitmap);
Notifybuilder.setsmallicon (SmallIcon);
Notifybuilder.setticker (Tickertext);
Notifybuilder.setcontentinfo (ContentInfo);
Notifybuilder.setcontenttitle (Contenttitle);
Notifybuilder.setcontenttext (ContentText);
Notifybuilder.setautocancel (FALSE);
Notifybuilder.setwhen (System.currenttimemillis ());
Notifybuilder.setdefaults (Notification.default_all);
Notifybuilder.setcontentintent (contentintent);
Notification Noti = Notifybuilder.build ();
Getnotificationmanager (Context). Notify (Notification_id_1, Noti);
}
public void showcustomviewnotify (context context, int smallicon,
Charsequence tickertext, int layoutid) {
Remoteviews mremoteviews = new Remoteviews (Context.getpackagename (),
LayoutID);
Pendingintent contentintent = pendingintent.getactivity (context, 0,
New Intent (context, Mainactivity.class), 0);
Notificationcompat.builder Notifybuilder = new Notificationcompat.builder (
context);
Notifybuilder.setsmallicon (SmallIcon);
Notifybuilder.setcontent (mremoteviews);
Notifybuilder.setticker (Tickertext);
Notifybuilder.setongoing (TRUE);
Notifybuilder.setautocancel (TRUE);
Notifybuilder.setdefaults (Notification.default_all);
Notifybuilder.setcontentintent (contentintent);
notification Noti = Notifybuilder.build ();
Intent dismissedintent = new Intent (
"com.xxxx.android.notify.dismissed");
/**
* The intent to execute when The notification is explicitly dismissed
* By the user, either with the ' Clear all ' "button or by swiping it away
* individually.
*
* This probably shouldn ' t is Launching an activity since several of
* Those would be sent at the same time.
*/
noti.deleteintent = Pendingintent.getbroadcast (context, 0,
dismissedintent, 0);
Getnotificationmanager (Context). Notify (Notification_id_2, Noti);
}
Public Notification getforegroundservicenotify (context context,
int SmallIcon, charsequence tickertext, Charsequence ContentInfo,
Charsequence Contenttitle, charsequence contenttext) {
Pendingintent contentintent = pendingintent.getactivity (context, 0,
New Intent (context, Mainactivity.class), 0);
Notificationcompat.builder Notifybuilder = new Notificationcompat.builder (
context);
Notifybuilder.setsmallicon (SmallIcon);
Notifybuilder.setticker (Tickertext);
Notifybuilder.setcontentinfo (ContentInfo);
Notifybuilder.setcontenttitle (Contenttitle);
Notifybuilder.setcontenttext (ContentText);
Notifybuilder.setautocancel (FALSE);
Notifybuilder.setcontentintent (contentintent);
Notifybuilder.setwhen (System.currenttimemillis ());
Notifybuilder.setdefaults (Notification.default_all);
return Notifybuilder.build ();
}
}
Android Notification Monitor system clears the notification bar method