It can be created in an activity or in a broadcast receiver, and can be created in a service.
Notificationmanager manager = (Notificationmanager) getsystemservice (Context.notification_service);
Creating a Notification object can be written as:
Notification Notification = new Notification (R.drawable.icon, "—————— This is ticker text ——————", System.currenttimemillis ());
When the icon just came out, it flashed. Time Created
Notification.setlatesteventinfo (Context, "This is the content title", "This iscontent text", null);
Title Body
Manager.notify (1, notification);//The number represents the ID, and the ID of each message should be different.
Pendingintent provides several static methods for obtaining pendingintent instances, which can be selected using the Getactivity () method, the Getbroadcast () method, or the GetService () method, depending on the requirements.
The first parameter is a context. The second parameter is passed in 0. The third parameter is a intent object that can be used to construct the pendingintent "intent" of the object.
The fourth parameter is used to determine the behavior of the pendingintent, with the four values of Flag_one_shot, Flag_no_create, Flag_cancel_current, and flag_update_current optional.
Intent Intent = new Intent (this, notificationactivity.class);
pendingintent pi = pendingintent.getactivity (this, 0, intent,pendingintent.flag_cancel_current);
Notification.setlatesteventinfo (This, "This is the content title", "This is content text", pi);//The fourth parameter is called Pendingintent.
Notificationmanager manager = (Notificationmanager) getsystemservice (Notification_service);
Manager.cancel (1);//Canceling the notification "1" is the ID that was passed in at the beginning.
Android Note: Notifications