Intent返回错误的数据

时间:2018-03-06 14:43:25

标签: android android-intent android-activity bundle android-pendingintent

我有这个功能来创建通知:

   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());

我现在发送beaconSettingID的硬编码值,例如: 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

我不明白? beaconID是" extra"的名称。关键之前。从那时起,我删除了应用程序,并将其更改为idToPass。但我仍然得到旧密钥,而不仅仅是错误的价值。为什么会这样?

1 个答案:

答案 0 :(得分:1)

删除应用并不意味着您删除了之前的通知。 尝试改变

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);

更新以前的通知

希望有所帮助