通知在android中计算

时间:2013-03-05 09:26:48

标签: android notifications

我在android中开发了Notification应用程序。但它没有显示通知的数量。

这是我的代码:

    int notificationCount = 0;

    private NotificationManager mgr=null;

    mgr=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

    Notification note=new Notification(R.drawable.chatpingicon, message+" says...",System.currentTimeMillis());

    PendingIntent i = PendingIntent.getActivity(this, -1, new Intent(this, HomeActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);

    Intent notifyIntent = new Intent(this, MyActivity.class);

    notifyIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    note.number = notificationCount++;

    noti.defaults = Notification.DEFAULT_ALL;

    noti.flags|=Notification.FLAG_AUTO_CANCEL;

    mgr.notify(NOTIFY_ME_ID++, noti);

1 个答案:

答案 0 :(得分:0)

Notification noti = new Notification.Builder(this)
        .setContentTitle("New mail from " + "test@gmail.com")
        .setContentText("Subject").setSmallIcon(R.drawable.ic_launcher)
        .getNotification();// deprecated in 4++

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;

notificationManager.notify(0, noti);
notificationManager.notify(1, noti);

为我显示了两个通知。通知计数看起来应该是什么?