Wednesday, November 3, 2010

Using Statusbar Notification in android

This is an example of using Status Bar Notification in Android. Notifications are using in Android to notify the user of events. The classes Notification and NotificationManager is used create notification. NotificationManager is a system service. We get the instance using getSystemService. The following code snippet creates a default notification:

NotificationManager notificationManager = (NotificationManager)getSystemService
(Context.NOTIFICATION_SERVICE);

int icon = R.drawable.icon;
CharSequence text = "Notification Text";
CharSequence contentTitle = "Notification Title";
CharSequence contentText = "Sample notification text.";
long when = System.currentTimeMillis();