@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//
Get a reference to the NotificationManager
NotificationManager
notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
//
Instantiate the Notification with an icon, ticker text, and when to be
displayed
int icon
= R.drawable.ic_launcher;
CharSequence
tickerText = "New notification";
long when
= System.currentTimeMillis(); //now
Notification
notification = new Notification(icon, tickerText, when);
//
Define the notification's message and PendingIntent
Context
context = getApplicationContext();
CharSequence
title = "Notification title";
CharSequence
text = "Notification description";
//
The activity PostNotification.class will be fired when notification will be
opened.
Intent
notificationIntent = new Intent(this, PostNotification.class);
PendingIntent
pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
//
Makes the notification disappear after clicked in the status bar
notification.flags|=Notification.FLAG_AUTO_CANCEL;
//
When the notification will be fired, notify the user with default
notification phone sound.
notification.defaults|=Notification.DEFAULT_SOUND;
notification.setLatestEventInfo(context,
title, text, pendingIntent);
//
Pass the Notification object to NotificationManager
notificationManager.notify(1,
notification);
}
|