gpt4 book ai didi

Android:服务类中的 intent.putExtra 以获取通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:33:15 25 4
gpt4 key购买 nike

这是我在服务类中的 showNotification 方法:

private void showNotification() {

Notification notification = new Notification(R.drawable.icon,
"New Notification", System.currentTimeMillis());

Intent i = new Intent(this, myActivity.class);
i.putExtra("notification", "MyNotif");
i.putExtra("notifiedby", "NotedBy");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);
notification.setLatestEventInfo(this, "NotedBy", "MyNotif", contentIntent);
nm.notify(111, notification);
}

所以在点击状态栏中的通知后,我将最终进入myActivity

问题是这些行总是在 myActivity 中给出 false

this.getIntent().hasExtra("notification")
this.getIntent().hasExtra("notifiedby")

putExtra() 不能与 PendingIntent 一起使用吗??

最佳答案

试试这个代码:

String notification = getIntent().getStringExtra("notification");
String notifiedby = getIntent().getStringExtra("notifiedby");

关于Android:服务类中的 intent.putExtra 以获取通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12820556/

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