所以这是我用于我的意图的代码:
TMP_VendorProductRate TMP_VendorProductRate
这是我创建动作的方式:
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);
Action2调用action2PendingIntent,动作调用action1PendingIntent。 但是在我的intentService中。我在onHandleIntent中有这个:
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();
}
但是bundle.getString(“tag”);将始终返回“#business”(第一个动作的标记,即使我按下第二个按钮。 为什么会这样?
答案 0 :(得分:1)
使用PendingIntent.FLAG_UPDATE_CURRENT上面提到的标志有助于更新活动的未决意图。
答案 1 :(得分:0)
感谢@pskink,我确实设法通过更改第二个待处理意图的请求代码使其工作,如下所示:
PendingIntent action2PendingIntent = PendingIntent.getService(context, 2,
action2Intent, PendingIntent.FLAG_ONE_SHOT);