How to:‎ > ‎

Create a status bar notification

Creating a title bar notification requires a few steps. First, you have to create a Notification object which represents the notification to be displayed. Then, create a PendingIntent for the notification to launch when the user taps it. Next, set the notification's details, updating its title, information, and the intent it should launch. Finally, use NotifcationManager to submit the notification to the system.

Here is an example:

// Create the notification
Notification notification = new Notification(R.drawable.icon, "New Good Deeds!", System.currentTimeMillis());
// Create an Intent for the notification to launch
Intent intent = new Intent(this, RecentDeeds.class);
// Create a PendingIntent for the associated Intent
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
// Set the notification's details
notification.setLatestEventInfo(getApplicationContext(), "New Good Deeds!", "New good deeds are waiting", pendingIntent);
// Submit the notification to the system
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification);

For more information, check here.