我有以下代码从服务创建通知。 我正在尝试额外发送不同的值,但每次都在接收方中获取最后一个设定值。
Intent closeButton = new Intent(this,DownloadCancelReceiver.class);
closeButton.putExtra("id",id);
closeButton.setAction("Action"+Long.toString(id));
PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, id, closeButton, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView = new RemoteViews(getPackageName(), R.layout.notification_view);
notificationView.setProgressBar(R.id.pb_progress, 100, 5, false);
notificationView.setOnClickPendingIntent(R.id.btn_close, pendingSwitchIntent);
最佳答案
您在 Pending Intent 中唯一需要更改的是 Extra 和 Action,然后出于优化目的,Android 正在重用旧 Intent。尝试将 PendingIntent.FLAG_UPDATE_CURRENT 更改为 PendingIntent.FLAG_CANCEL_CURRENT
要创建 PendingIntent,请尝试:
PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, id, closeButton, PendingIntent.FLAG_CANCEL_CURRENT);
关于android - pendingIntent 中未更新的额外值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42997350/