Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.