O'Reilly logo

Android Application Development For Dummies, 2nd Edition by Donn Felker, Michael Burton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the Notification Manager

You use the Notification Manager to interact with the Android notification mechanism. Working with the Notification Manager is as simple as requesting it from the current context.

The following line of code obtains the NotificationManager object from the getSystemService() call of Context:

NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

Creating a notification

The Task Reminder application needs a way to notify the user that a task needs attention, such as an alarm signifying that task. To set this notification on the status bar, you use the NotificationManager.

In the doReminderWork() method of the ReminderService class, type the code shown in Listing 14-1.

Listing 14-1: Implementation of doReminderWork()

Long rowId = intent.getExtras().getLong(ReminderProvider.COLUMN_ROWID); →1

NotificationManager mgr =

(NotificationManager)getSystemService(NOTIFICATION_SERVICE); →4

Intent notificationIntent = new Intent(this, ReminderEditActivity.class); →6

notificationIntent.putExtra(ReminderProvider.COLUMN_ROWID, rowId); →7

PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT); →9

Notification note=new Notification(android.R.drawable.stat_sys_warning,

getString(R.string.notify_new_task_message),

System.currentTimeMillis()); →14

note.setLatestEventInfo(this, getString(R.string.notify_new_task_title),

getString(R.string.notify_new_task_message), pi); →17

note.defaults ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required