Nikitas
Nikitas

Reputation: 649

Callback on "clear all" button in notification area

I am developing and android app where i have to count how many times the app started through a notification. My problem is that i can't catch the event where the user presses "clear button" from the notification area. Is there any way or a callback in order to know when the clear button pressed?

I have read about deleteIntent but i don't know how to use it.

Thank you in advance

Upvotes: 3

Views: 1902

Answers (1)

Andrew
Andrew

Reputation: 8090

Create a deleteIntent

Intent deleteIntent = new Intent(context, NotificationReceiver.class);
deleteIntent.setAction("delete");

Attach it to your notification

notification.deleteIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, 0);

Create a new class to pick up on the delete intent

public class NotificationReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("TEST", "Clear app processing here");
    }
}

Add to your manifest file

<receiver android:name=".NotificationReceiver" 
      android:enabled="true">
</receiver>

Upvotes: 6

Related Questions