0

我有一种创建通知的方法。我想在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);
}
4

1 回答 1

0

If by "I want to clear notification number" you mean you want to keep the notification itself still displayed, but you want just to update/remove counter, then you should set your notification PendingIntent to point to your code that would handle this scenario for you, and when it completes it shall redirect to your target TabInterfaceActivity (or you can make it more flexible and pass target in PendingIntent's Bundle).

于 2012-09-10T15:39:11.043 回答