3

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

braX
  • 11,506
  • 5
  • 20
  • 33
Nikitas
  • 649
  • 4
  • 9
  • 18

1 Answers1

6

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>
Andrew
  • 7,548
  • 7
  • 50
  • 72