だから、これは私が私の意図に使用するコードです:第二ボタン、私はIntentServiceで受信バンドルには、エキストラを含む最初のボタンから
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);
は、これは私がアクションを作成する方法である:
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はaction2PendingIntentを呼び出し、アクションはaction1PendingIntentを呼び出します。 しかし、私のintentServiceで。私は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);
}
しかし、bundle.getString( "tag");
使用異なるrequestCodes .getServiceを呼び出します() – pskink