我们如何检测通知取消? [英] How can we detect notification cancel?
问题描述
我如何作出反应的通知辞退?我要杀死我的后台进程的时候一定通知被取消。
How can I react on notification dismiss? I need to kill my background process when a certain notification is cancelled.
在此主题,它说使用广播接收器,但没有任何意图滤波器,用于通知
In this thread it says use a broadcast receiver, but there is no intent-filter for notifications
<一个href="http://stackoverflow.com/questions/8811876/notification-deleteintent-does-not-work">Notification deleteIntent不起作用
推荐答案
您不需要意图过滤器来获得广播,如果你定义了意向手工触发类。
You don't need an intent-filter to get a broadcast if you define the Intent to trigger your class by hand.
刚刚实施的BroadcastReceiver
Just implement the BroadcastReceiver
public class NotificationDeleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// kill service here
}
}
和接收器添加到的AndroidManifest.xml
And add the Receiver to the AndroidManifest.xml
<receiver android:name="NotificationDeleteReceiver" />
然后设置PendingIndent到通知:
Then set the PendingIndent to the notification:
notification.deleteIntent = PendingIntent.getBroadcast(
this, 0, new Intent(context, NotificationDeleteReceiver.class), 0);
这会工作。
这篇关于我们如何检测通知取消?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!