0

Ich erstelle eine Chat-Anwendung mit Firebase. Ich sende Benachrichtigungen mit Firebase Cloud Funktionen und empfange sie auf meinem Handy. Aber für jede Nachricht erhalte ich eine neue Benachrichtigung. Und jetzt möchte ich wissen, ob es möglich ist, eine Benachrichtigung wie in WhatsApp zu erstellen, mit mehreren Zeilen für jede Nachricht in einer Benachrichtigung. Mein-Code für eine Benachrichtigung:ChatApp: Multiline-Benachrichtigungen

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    String notification_tag = remoteMessage.getData().get("senderUiD"); 

     Intent intent = new Intent(getApplicationContext(), Chat_Room.class); 

     PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); 

     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext()) 
       .setSmallIcon(R.mipmap.ic_launcher) 
       .setContentTitle(remoteMessage.getData().get("username")) 
       .setContentText(remoteMessage.getNotification().getBody()) 
       .setVibrate(new long[]{1500, 0, 1500, 0}) 
       .setLights(Color.BLUE, 2000, 1000) 
       .setWhen(remoteMessage.getSentTime()) 
       .setAutoCancel(true) 
       .setPriority(NotificationCompat.PRIORITY_HIGH) 
       .setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getNotification().getBody())) 
       .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) 
       .setContentIntent(pendingIntent); 

     notificationManager.notify(notification_tag, 0, notificationBuilder.build()); 

Danke für Ihre Hilfe;)

+0

Ich empfehle Ihnen dringend, diese Links zu lesen: https://stackoverflow.com/questions/33040737/how-to-group-android-notifications-like-whatsapp https://stackoverflow.com/questions/41692501/ Gruppenbenachrichtigungen-auf-Android –

Antwort

0

Wenn Sie erhalten Notification Nachricht Ihre Notification In Überschreibung letzten Notification

erzeugen Rendam Anzahl

Random ran = new Random(); 
int notification_tag = r`an.nextInt(6) + 5;` 

notificationManager.notify(notification_tag, 0, notificationBuilder.build()); 

auch Wenige Schritte zum Gruppieren der Meldung

NotificationCompat.Builder:contains the UI specification and action information 
NotificationCompat.Builder.build() :used to create notification (Which returns Notification object) 
Notification.InboxStyle: used to group the notifications belongs to same ID 
NotificationManager.notify():to issue the notification. 
Verwandte Themen