Android中有一个状态栏图标的多个通知

Kan*_*dha 7 notifications android

我正在使用自定义通知...如何设置不显示通知?并列出这些通知?这是我的代码......

public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "coming", Toast.LENGTH_LONG).show();
        Bundle descBundle = intent.getExtras();
        CharSequence desc = descBundle.getString("description");
        int reminderId = descBundle.getInt("reminderId");
        NotificationManager mNotificationManager;
        mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        PendingIntent contentIntent = PendingIntent.getActivity(context,
                reminderId, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
        RemoteViews contentView = new RemoteViews(context.getPackageName(),
                R.layout.main);
        contentView.setImageViewResource(R.id.image, R.drawable.reminder_1);
        contentView.setTextViewText(R.id.text, desc);
        Notification notifyDetails = new Notification();
        notifyDetails.icon = R.drawable.reminder_1;
        notifyDetails.when = System.currentTimeMillis();
        notifyDetails.tickerText = desc;
        notifyDetails.iconLevel = 1;
        notifyDetails.number = reminderId;
        notifyDetails.contentView = contentView;
        notifyDetails.contentIntent = contentIntent;
        mNotificationManager.notify(0, notifyDetails);
    }
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码显示通知...但它只显示一个通知内容...但图标显示没有通知...

Chr*_*Orr 2

每个图标对应一个通知;您不能将多个通知与通知栏上的一项的一个实例关联。

但是,您可以像某些 SMS 和电子邮件应用程序一样,在图标顶部叠加一个数字(例如,显示图标代表的事件数量)。

这是通过number实例变量完成的Notification,如上面的代码片段中所示。

编辑:
更清楚地说:如果您想要多个通知,则需要创建多个Notification对象并NotificationManager.notify()多次调用。

每个Notification只能产生一个图标,可以在通知区域内拥有一项内容,并且可以有一个Intent与之关联的内容。