Skip to content

Instantly share code, notes, and snippets.

@felipecaldas
Created March 14, 2013 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipecaldas/5161512 to your computer and use it in GitHub Desktop.
Save felipecaldas/5161512 to your computer and use it in GitHub Desktop.
public class NotifyService extends Service {
private final int NOTIFICATION_ID = 1;
@Override
public void onCreate() {
NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//R.drawable.ic_launcher is the icon for this notification
Notification notification = new Notification(R.drawable.ic_launcher, "This is the message that first appread in the top bar", System.currentTimeMillis());
Intent myIntent = new Intent(this , MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
notification.setLatestEventInfo(this, "This is the label of the notification", "Text to show in the notification", contentIntent);
//Adding this Flag so that when user clicks on the notification, it closes (cancels)
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION_ID, notification);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment