I'm implementing push notifications on my application. Unfortunately, after implementing them these are not shown on some devices. In general, I can try the application on MIUI devices and the notifications are shown correctly. On android stock instead (such as the emulator), these are not shown. I'm sure the notification arrives on the devices because the function that shows the notification is called, but nothing is shown. Could you help me?
Thanks!
private final String NOTIFICATION_CHANNEL_ID = "XXXXX_CHAT_CHANNEL";
private final String GROUP_KEY_CHAT = "XXXXX_GROUP_CHANNEL";
private static NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
private static int messageRecived = 0;
private void SendNotification(String body, String title){
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("firstKeyName","FirstKeyValue");
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
if(!isNotificationVisible()){
messageRecived = 0;
inboxStyle = null;
inboxStyle = new NotificationCompat.InboxStyle();
}
Notification summaryNotification;
if(messageRecived == 0){
inboxStyle.addLine(title +": " + body);
messageRecived += 1;
summaryNotification =
new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(R.drawable.ic_logo)
.setGroup(GROUP_KEY_CHAT)
.setGroupSummary(true)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
} else {
inboxStyle.addLine(title +": " + body);
inboxStyle.setBigContentTitle("Messaggi");
messageRecived += 1;
summaryNotification =
new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setContentTitle("xxxxxxx")
.setContentText("Ci sono " + messageRecived + " nuovi messaggi")
.setSmallIcon(R.drawable.ic_logo)
.setStyle(inboxStyle)
.setGroup(GROUP_KEY_CHAT)
.setGroupSummary(true)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
}
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(MessageHandler.getInstance().getNotificationID(), summaryNotification);
}