gpt4 book ai didi

android - 为什么在 android 通知 Intent 中不发送额外数据(整数)?

转载 作者:太空狗 更新时间:2023-10-29 15:32:53 26 4
gpt4 key购买 nike

以下代码显示通知并发送 int 数据,但在另一个 Activity getExtras() 中返回 null。为什么?

int notificationID = 1;
NotificationManager nm = (NotificationManager) getSystemService(getApplicationContext().NOTIFICATION_SERVICE);


Intent i = new Intent(getApplicationContext(), DownlodResult.class);
i.putExtra("notificationID", 1);


PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, i, 0);


CharSequence tickerText = "There are updates !";
long when = System.currentTimeMillis();
int icon = R.drawable.ic_launcher;
Notification notification = new Notification(icon,tickerText,when);
CharSequence contentTitle = "There are updates";
CharSequence contentText = "Please click here to view it";
notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);



notification.vibrate = new long[] { 100, 250, 100, 500}; // Needs vibrate permissions
nm.notify(notificationID, notification);

最佳答案

可能 PendingIntent 已经存在并且没有被创建,但是被重用了。尝试使用 PendingIntent.FLAG_UPDATE_CURRENT 标志创建它:

PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

参见 https://stackoverflow.com/a/9330144/530804以及关于该问题的其他答案。

关于android - 为什么在 android 通知 Intent 中不发送额外数据(整数)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10456655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com