Last active
August 29, 2015 13:59
-
-
Save SeanPONeil/10669008 to your computer and use it in GitHub Desktop.
displayExpandedNotificationWithMultipleActions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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