【发布时间】:2013-09-07 20:19:16
【问题描述】:
我如何对通知关闭做出反应?当某个通知被取消时,我需要终止我的后台进程。
在这个线程中它说使用广播接收器,但没有用于通知的意图过滤器
【问题讨论】:
标签: android notifications
我如何对通知关闭做出反应?当某个通知被取消时,我需要终止我的后台进程。
在这个线程中它说使用广播接收器,但没有用于通知的意图过滤器
【问题讨论】:
标签: android notifications
如果您定义意图手动触发您的类,则不需要意图过滤器来获取广播。
只需实现广播接收器
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);
这会起作用。
【讨论】: