Java 如何使用Firebase云消息在前台显示多个通知
我在Android中有一个应用程序,它接收来自firebase的通知,但当它在前台时,新的通知将取代以前的通知。我怎样才能把一切都展示出来? 这是我的课 公共类FirebaseNotifications扩展了FirebaseMessagingService { 私有静态最终字符串TAG=“MyFirebaseMsgService” }我决定Java 如何使用Firebase云消息在前台显示多个通知,java,android,firebase-cloud-messaging,Java,Android,Firebase Cloud Messaging,我在Android中有一个应用程序,它接收来自firebase的通知,但当它在前台时,新的通知将取代以前的通知。我怎样才能把一切都展示出来? 这是我的课 公共类FirebaseNotifications扩展了FirebaseMessagingService { 私有静态最终字符串TAG=“MyFirebaseMsgService” }我决定 private final static AtomicInteger c = new AtomicInteger(0); public stati
private final static AtomicInteger c = new AtomicInteger(0);
public static int getID() {
return c.incrementAndGet();
}
private void sendNotification(String messageBody, String icon)
{
String channelId = "General";
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setLargeIcon(getBitmapFromURL(icon))
.setContentTitle("Chapur")
.setSmallIcon(R.drawable.icon_agenda)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(getID(), notificationBuilder.build());
}
您的问题是,您总是在行中使用“0”作为notif ID notificationManager.notify(0,notificationBuilder.build()) 如果你每次都给它一个新的id,你就不会有这个问题:)
private final static AtomicInteger c = new AtomicInteger(0);
public static int getID() {
return c.incrementAndGet();
}
private void sendNotification(String messageBody, String icon)
{
String channelId = "General";
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setLargeIcon(getBitmapFromURL(icon))
.setContentTitle("Chapur")
.setSmallIcon(R.drawable.icon_agenda)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(getID(), notificationBuilder.build());
}