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
You don't need an intent-filter to get a broadcast if you define the Intent to trigger your class by hand.
Just implement the BroadcastReceiver
public class NotificationDeleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// kill service here
}
}
And add the Receiver to the AndroidManifest.xml
<receiver android:name="NotificationDeleteReceiver" />
Then set the PendingIndent to the notification:
notification.deleteIntent = PendingIntent.getBroadcast(
this, 0, new Intent(context, NotificationDeleteReceiver.class), 0);
This will work.