So this is the code I use for my intents:
String tag = "#business"; String secondTag = "#personal";
Intent action1Intent = new Intent(context, NotificationActionService.class)
.setAction("tag").putExtra("id", psTrip.getId()).putExtra("tag", tag);
PendingIntent action1PendingIntent = PendingIntent.getService(context, 0,
action1Intent, PendingIntent.FLAG_ONE_SHOT);
Intent action2Intent = new Intent(context, NotificationActionService.class)
.setAction("tag").putExtra("id", psTrip.getId()).putExtra("tag", secondTag);
PendingIntent action2PendingIntent = PendingIntent.getService(context, 0,
action2Intent, PendingIntent.FLAG_ONE_SHOT);
This is how I create the actions:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
RemoteInput remoteInput = new RemoteInput.Builder("Business")
.setLabel("Business")
.build();
Notification.Action action =
new Notification.Action.Builder(R.drawable.btn_tag_trip,
tag, action1PendingIntent)
.addRemoteInput(remoteInput)
.build();
RemoteInput remoteInput2 = new RemoteInput.Builder("Personal")
.setLabel("Personal")
.build();
Notification.Action action2 =
new Notification.Action.Builder(R.drawable.btn_tag_trip,
secondTag, action2PendingIntent)
.addRemoteInput(remoteInput2)
.build();
noti = new Notification.Builder(context)
.setContentTitle(context.getString(R.string.passenger_name))
.setContentText(content).setSmallIcon(R.drawable.notification_icon)
.setContentIntent(pIntent)
.addAction(action)
.addAction(action2).build();
}
Action2 calls action2PendingIntent and action calls action1PendingIntent. But in my intentService. I have this in my onHandleIntent:
final NotificationManager notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notifManager.cancelAll();
String action = intent.getAction();
Log.i("", "Received notification action: " + action);
Bundle bundle = intent.getExtras();
if (bundle != null) {
final String id = bundle.getString("id");
final String tag = bundle.getString("tag");
Log.i("", "Received notification action: id: " + id + " / tag: " + tag);
}
BUT the bundle.getString("tag"); will always return "#business" (the tag of the first action, even if I press the second button. Why is this happening?
Thanks to @pskink I did manage to make it work, by changing the request code for the second pending intent, like this: