【问题标题】:How can we detect notification cancel?我们如何检测通知取消?
【发布时间】:2013-09-07 20:19:16
【问题描述】:

我如何对通知关闭做出反应?当某个通知被取消时,我需要终止我的后台进程。

在这个线程中它说使用广播接收器,但没有用于通知的意图过滤器

Notification deleteIntent does not work

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    如果您定义意图手动触发您的类,则不需要意图过滤器来获取广播。

    只需实现广播接收器

    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);
    

    这会起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 2018-07-05
      • 2016-05-18
      • 1970-01-01
      • 2017-03-26
      • 1970-01-01
      相关资源
      最近更新 更多