Skip to content

Instantly share code, notes, and snippets.

@SeanPONeil
Last active August 29, 2015 13:59
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 SeanPONeil/10667860 to your computer and use it in GitHub Desktop.
Save SeanPONeil/10667860 to your computer and use it in GitHub Desktop.
displayNotificationWithOneAction
public void displayNotification(String title, String message, int icon, int id) {
// Create PendingIntent that launches an activity
Intent intent = new Intent(getContext(), LoginRequestActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
// Build the notification
Notification notification = new NotificationCompat.Builder()
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon)
.setContentIntent(pendingIntent)
.build();
// Post the notification
NotificationManager nm = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(id, notification);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment