何时清除android中状态通知的通知计数

时间:2012-09-10 15:10:42

标签: android notifications

我有一种创建通知的方法。我想在用户点击状态通知后立即清除通知number

public void createNotification(){

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification notification=null;
        notification = new Notification(R.drawable.ic_launcher, "You have a new message", System.currentTimeMillis());

        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.number = **count**++;
        Intent intent = new Intent();
            intent.setClass(TabInterfaceActivity.this, TabInterfaceActivity.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent activity = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        notification.contentIntent = activity;
        notification.setLatestEventInfo(this, " New Message", message, notification.contentIntent);
}

1 个答案:

答案 0 :(得分:0)

如果通过“我要清除通知编号”表示您希望保持通知本身仍然显示,但您只想更新/删除计数器,则应将通知PendingIntent设置为指向将为您处理此方案的代码,当它完成时,它将重定向到您的目标TabInterfaceActivity(或者您可以使其更灵活并在PendingIntent的Bundle中传递目标)。