Android notication usage
private void sendNotification() {// TODO Auto-generated method stubNotificationManager manager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);Notification notification = new Notification();notification.icon = R.drawable.ic_launcher;notification.tickerText = "I am in the state bar!";notification.audioStreamType = android.media.AudioManager.ADJUST_LOWER;Intent intent = new Intent(this, secondActivity.class );PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);notification.setLatestEventInfo(this, "Content Title","Content", pendingIntent);manager.notify(1,notification);}
Code explanation:
1: Obtain icationicationmanager:
Icationicationmanager m_notificationmanager = (notificationmanager) This. getsystemservice (icationication_service );
2: Define a notification:
Notification m_notification = new notification ();
3: set various attributes of notification:
// Set the notification icon
M_icationication.icon = R. drawable. Icon;
// Content displayed when we click the notification
M_icationication.tickertext = "button1 notification content .....";
// Send the default sound during notification
M_icationication.defaults = notification. default_sound;
// Set notification display parameters
Intent m_intent = new intent (icationicationdemo. This, desactivity. Class );
Pendingintent m_pendingintent = pendingintent. getactivity (icationicationdemo. This, 0, m_intent, 0 );
M_icationication.setlatesteventinfo (icationicationdemo. This, "button1", "button1 notification", m_pendingintent );
// Start Execution Notification
M_icationicationmanager.policy (0, m_notification );
4: Now that you can delete a new one.
M_icationicationmanager.cancel (0 );
This 0 is an idnumber, which is the same as the first parameter 0 of policy.