Callback on “clear all” button in notification area

久未见 提交于 2019-12-12 15:18:17

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/13976634/callback-on-clear-all-button-in-notification-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!