我有这个函数来创建通知:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(title)
.setSound(alarmSound)
.setContentText(subtitle);
if(haveIntent) {
Intent intent = new Intent(context, PSBeaconMainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("idToPass", beaconSettingID);
PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
mBuilder.setContentIntent(pIntent);
}
int mNotificationId = 001;
NotificationManager mNotifyMgr =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
我现在发送信标设置ID的硬编码值,例如:https://scontent-amt2-1.xx.fbcdn.net/v/t35.0-12/28822214_1907084479363661_711965391_o.png?oh=b4c247836bcbd572d27f53738d2bdf6c&oe=5AA0C75E
这是我的getIntent.getBundle:
if (bundle != null && bundle.containsKey("idToPass")) {
beaconUUID = bundle.getString("idToPass");
}
但我得到这个:https://scontent-amt2-1.xx.fbcdn.net/v/t35.0-12/28768405_1907084916030284_1955200830_o.png?oh=bcccf27352c90b248e82e08d902b8c15&oe=5AA1BA02
我不明白? 信标ID之前是"额外"密钥的名称。从那以后,我删除了该应用程序,并将其更改为idToPass。但我仍然得到旧密钥,更重要的是,它的值是错误的。为什么会这样?
删除应用并不意味着您删除了之前的通知。尝试改变
PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
自:
PendingIntent pIntent = PendingIntent.getActivity(context, SOME_UNIQUE_ID, intent, 0);
为了创建新的
或:
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
更新以前的通知
希望对你有帮助