在Android中,如何从同一个应用程序发送不同类型的推送通知

在Android中,如何从同一个应用程序发送不同类型的推送通知,android,push-notification,google-cloud-messaging,Android,Push Notification,Google Cloud Messaging,在Android中,当您收到相同类型的推送通知时,最新的推送通知将取代通知屏幕中的前一个推送通知,这很可能是为了防止混乱。然而,我看到在一些应用程序中,我从同一个应用程序中获得的通知并不取代以前的通知。如何对我的应用程序进行编程以实现这一点?为了在状态栏上显示多个通知,您所要做的就是为您想要的每个通知设置一个唯一的通知ID。如果发送两个具有相同ID的通知,则通知管理器会将最旧的通知替换为最新的通知。查看的notify方法 以下是如何发送通知的示例: Notification notificati

在Android中,当您收到相同类型的推送通知时,最新的推送通知将取代通知屏幕中的前一个推送通知,这很可能是为了防止混乱。然而,我看到在一些应用程序中,我从同一个应用程序中获得的通知并不取代以前的通知。如何对我的应用程序进行编程以实现这一点?

为了在状态栏上显示多个通知,您所要做的就是为您想要的每个通知设置一个唯一的通知ID。如果发送两个具有相同ID的通知,则通知管理器会将最旧的通知替换为最新的通知。查看的notify方法

以下是如何发送通知的示例:

Notification notification = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(title)
            .setContentText(message)
            .setAutoCancel(true)
            .setSound(alarmSound)
            .setPriority(Notification.PRIORITY_MAX)
            .build();

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationId, notification);

确保
通知ID
是唯一的,否则它将用相同的ID替换最旧的通知。

为了在状态栏上有多个通知,您所要做的就是为您想要的每个通知设置一个唯一的通知ID。如果发送两个具有相同ID的通知,则通知管理器会将最旧的通知替换为最新的通知。查看的notify方法

以下是如何发送通知的示例:

Notification notification = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(title)
            .setContentText(message)
            .setAutoCancel(true)
            .setSound(alarmSound)
            .setPriority(Notification.PRIORITY_MAX)
            .build();

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationId, notification);

确保
通知ID
是唯一的,否则它将用相同的ID替换最旧的通知。

@user2911983-有用吗?@user2911983-有用吗?