Notification and Notificationmanager
The 1.Broadcast Receiver component does not provide a visual interface to display broadcast information. Here we can use notification and Notificationmanager to visualize the information display. By using them we can display the contents of the broadcast message, the icon
and vibration and other information.
2. The use of notification and Notificationmanager is also relatively simple, generally obtain a system-level service Notificationmanager, and then instantiate notification, set its properties, It is possible to send a notice via Notificationmanager.
The basic steps are as follows:
1) obtain system-level service Notificationmanager, here is relatively simple, through the Context.getsystemservice () method can be achieved.
1 String service = Notification; 2 notificationmanager nm = (notificationmanager) getsystemservice (service);
2) Instantiate the notification object and set its properties.
// Instantiate notification New Notification (); // Who knows the display icon, the icon will appear in the status bar int icon = N.icon = R.drawable.icon; // Set the display prompt message, String tickrttext = "Test Notification"; // Show Time long when == = when;
3) Call the Setlatestecentinfo () method to set the icon and time in the view
Instantiate intent
New Intent (This, mainactivity. Class); // Get Pendingintent pendingintent pi = pendingintent . getactivity (This, 0,intent,0); // Set Time information n.setlasteventinfo (This, "My content", "My Content", pi);
4) Giving Notice
// represents the ID of the notification int ID = 1; // notification nm.notify (id,n);
3. The following is a direct example of how