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/10669008 to your computer and use it in GitHub Desktop.
Save SeanPONeil/10669008 to your computer and use it in GitHub Desktop.
displayExpandedNotificationWithMultipleActions
public void displayNotification(String title, String message, int smallIcon, int largeIcon) {
// Create PendingIntent that launches an activity
Intent intent = new Intent(getContext(), LoginRequestActivity.class);
PendingIntent activityIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
// Build the notification
Notification notification = new NotificationCompat.Builder()
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(smallIcon)
.setLargeIcon(largeIcon)
.setContentIntent(activityIntent)
.addAction(R.drawable.ic_approve_action, "Approve", getBroadcastIntent("Approve"))
.addAction(R.drawable.ic_deny_action, "Deny", getBroadcastIntent("Deny"))
.build();
// Post the notification
NotificationManager nm = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(id, notification);
}
// Create PendingIntent that broadcasts what action was clicked
public void PendingIntent getBroadcastIntent(String action) {
Intent intent = new Intent(getContext().getPackageName() + "." + action);
intent.putExtra("action", action);
return PendingIntent.getBroadcast(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment