Skip to content

Instantly share code, notes, and snippets.

@adriantache
Last active May 22, 2018 15:41
Show Gist options
  • Save adriantache/9692aa2d4d5bc32a60e8e06311291a51 to your computer and use it in GitHub Desktop.
Save adriantache/9692aa2d4d5bc32a60e8e06311291a51 to your computer and use it in GitHub Desktop.
Notification Building code
private final static String manasia_notification_channel = "Manasia Event Reminder";
//get latest event details
String notificationTitle = "Manasia event: " + event.getTitle();
String notificationText = event.getDate() + " at Stelea Spatarul 13, Bucuresti";
//build the notification
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(getApplicationContext(), manasia_notification_channel)
.setSmallIcon(R.drawable.ic_manasia_small)
.setContentTitle(notificationTitle)
.setContentText(notificationText)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
//trigger the notification
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(getApplicationContext());
//we give each notification the ID of the event it's describing,
//to ensure they all show up and there are no duplicates
notificationManager.notify(DBEventID, notificationBuilder.build());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment