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
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
如果您定义意图来手动触发您的类,则不需要意图过滤器来获得广播。
只需实现 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);
这将起作用。