gpt4 book ai didi

java - 如何区分通知点击和通知按钮点击

转载 作者:行者123 更新时间:2023-11-30 10:23:25 25 4
gpt4 key购买 nike

当我点击通知时它自己和操作按钮它做同样的事情,我想区分它们,我希望按钮做一些事情,当我点击通知时它自己做其他事情,这是我的代码 -

    Intent intent = new Intent(this, NotificationView.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setTicker(getString(R.string.notificationticker))
.setContentTitle(getString(R.string.notificationtitle))
.setContentText(yeah)
.addAction(R.drawable.ic_favorite, getString(R.string.azor), pIntent)
.setContentIntent(pIntent)
.setAutoCancel(true);

NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());

最佳答案

将不同的 PendingIntents 传递给 addActionsetContentIntent
目前它们都使用相同的 pIntent 实例。

如果您希望它们都启动相同的 Activity 但执行不同的操作,您可以向 Intent 添加 extra,以用于创建待定 Intent。

关于java - 如何区分通知点击和通知按钮点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47003475/

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