gpt4 book ai didi

android - 我们如何检测通知取消?

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:45 24 4
gpt4 key购买 nike

我如何对通知关闭使用react?当某个通知被取消时,我需要终止我的后台进程。

在这个线程中它说使用广播接收器,但是没有用于通知的 intent-filter

Notification deleteIntent does not work

最佳答案

如果您定义了手动触发类的 Intent,则不需要 intent-filter 来获取广播。

只需实现 BroadcastReceiver

public class NotificationDeleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// kill service here
}
}

并将Receiver添加到AndroidManifest.xml

<receiver android:name="NotificationDeleteReceiver" />

然后给通知设置PendingIndent:

notification.deleteIntent = PendingIntent.getBroadcast(
this, 0, new Intent(context, NotificationDeleteReceiver.class), 0);

这会起作用。

关于android - 我们如何检测通知取消?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18673155/

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