Skip to content

Instantly share code, notes, and snippets.

@mortenjust
Last active August 29, 2015 14:26
Show Gist options
  • Save mortenjust/018a81ee7917a6f516c6 to your computer and use it in GitHub Desktop.
Save mortenjust/018a81ee7917a6f516c6 to your computer and use it in GitHub Desktop.
Android Notification
public void sendNotification(){
// set up notification
int NOTIFICATION_ID = 0;
PendingIntent activityPendingIntent = getActivityPendingIntent();
Notification n = new NotificationCompat.Builder(this)
.setContentTitle("You won!")
.setContentText("A trip to the neighbors")
.setSmallIcon(R.drawable.abc_btn_radio_material)
.setContentIntent(activityPendingIntent)
.build();
NotificationManagerCompat nm = NotificationManagerCompat.from(this);
nm.notify(NOTIFICATION_ID, n);
}
public PendingIntent getActivityPendingIntent(){
Intent activityIntent = new Intent(this, MainActivity.class);
activityIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
return PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment