Android Tutorial

(avery) #1

By : Ketan Bhimani


414 

Additionally, you can set notification information through public
member variable assignment, like this:

notify.icon = R.drawable.android_32;
notify.tickerText = "Hello!";
notify.when = System.currentTimeMillis();


You need to set a couple more pieces of information before the call
to the notify() method takes place. First,we need to make a call to
the setLastEventInfo() method, which configures a View that
displays in the expanded status bar. Here is an example:

Intent toLaunch = new Intent
(SimpleNotificationsActivity.this,
SimpleNotificationsActivity.class);
PendingIntent intentBack = PendingIntent.getActivity
(SimpleNotificationsActivity.this, 0, toLaunch, 0);
notify.setLatestEventInfo(SimpleNotificationsActivity.this,
"Hi there!", "This is even more text.", intentBack);


Next, use the notify() method to supply the notification’s title and
body text as well as the Intent triggered when the user clicks on
the notification. In this case, we’re using our own Activity so that
when the user clicks on the notification, our Activity launches
again.

Working with the Notification Queue

Now the application is ready to actually notify the user of the
event. All that is needed is a call to the notify() method of the
NotificationManager with an identifier and the Notification we
configured. This is demonstrated with the following code:

private static final int NOTIFY_1 = 0x1001;
// ...
notifier.notify(NOTIFY_1, notify);

Free download pdf