我正在创建一个具有多个操作的
因此,通知已成功创建。按钮都在那里。但是,无论我按哪个按钮,传递给
我想不通为什么-这4个
notification
。 我正在使用 broadcast intents
来通信,以便在推送其中一个时采取特定操作。 有 4 个按钮,我已经创建了 4 个单独的意图。 每个意图都具有相同的操作字符串,但是不同的 StringExtra
。Intent intNow = new Intent(mThis, MyReceiver.class).setAction(actionNotify).putExtra("button", ACT_NOW);
Intent intEmail = new Intent(mThis, MyReceiver.class).setAction(actionNotify).putExtra("button", ACT_EMAIL);
Intent intLater = new Intent(mThis, MyReceiver.class).setAction(actionNotify).putExtra("button", ACT_LATER);
Intent intNever = new Intent(mThis, MyReceiver.class).setAction(actionNotify).putExtra("button", ACT_NEVER);
Notification.Builder myRatingNotification = new Notification.Builder(mThis)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.mipmap.ic_launcher)
.addAction(0, mThis.getString(R.string.Rate_Act_Now), PendingIntent.getBroadcast(mThis, 0, intNow, PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(0, mThis.getString(R.string.Rate_App_Email), PendingIntent.getBroadcast(mThis, 0, intEmail, PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(0, mThis.getString(R.string.Rate_Act_Later), PendingIntent.getBroadcast(mThis, 0, intLater, PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(0, mThis.getString(R.string.Rate_Act_Never), PendingIntent.getBroadcast(mThis, 0, intNever, PendingIntent.FLAG_UPDATE_CURRENT))
.setAutoCancel(true);
Notification notification = new Notification.BigTextStyle(myRatingNotification).bigText(text).build();
((NotificationManager) mThis.getSystemService(Context.NOTIFICATION_SERVICE)).notify(notificationId, notification);
因此,通知已成功创建。按钮都在那里。但是,无论我按哪个按钮,传递给
receiver
的额外信息始终是最后一个定义的操作。也就是说,在上面的示例中,每个按钮都返回一个等于ACT_NEVER
的字符串额外信息。如果我重新排列.addAction
,使intLater成为最后一个,接收器会告诉我字符串额外信息等于ACT_LATER
,无论我按哪个按钮。我想不通为什么-这4个
Intents
完全独立于彼此。动作指定了正确的Intent
。发生了什么?我很困惑。