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

标签 android notifications

我如何对通知关闭使用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/

相关文章:

安卓视频转换

android - 视频监听器正在运行

android - 使用 Notification Listener 捕获堆叠的通知

javascript - 浏览器通知调用网站

java - 为什么 float 用 1 除以 2 或 4 时返回 0?

android - 是否有使用 ExoPlayer 实现 DASH 的非 YouTube 示例?

android - gradle - 接口(interface) org.gradle.api.Action 如何工作?

安卓通知: GCM or Service

java - 我们可以使用 JMX 进行警报/通知吗

firebase - 如何设置 pubsub 以便 firebase 可以通过云函数 pubsub 触发器接收?