How I can create notification with action buttons like Gmail app notification?
Asked
Active
Viewed 1,174 times
0
-
https://developer.android.com/guide/topics/ui/notifiers/notifications.html – IntelliJ Amiya Jul 13 '17 at 10:27
-
Check the below link, https://stackoverflow.com/questions/20748049/android-multiple-line-notification-like-gmail-app – taug Jul 13 '17 at 10:28
1 Answers
0
you can add following code
public void createNotification() {
// Prepare intent which is triggered if the
// notification is selected
Intent intent = new Intent(this, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject").setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.addAction(R.drawable.delete, "Delete", pIntent)
.addAction(R.drawable.reply, "reply", pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
}

Avinash
- 264
- 5
- 15
-
But this addAction method available in android 22 and above, how I can handle this in older versions? @Avinash – BahaaIddin Al Sharqawi Jul 13 '17 at 11:06
-