android 上未显示推送通知

Push Notifications are not showing on android

我正在我的应用程序上实施推送通知。不幸的是,在实施它们之后,这些不会在某些设备上显示。总的来说,我可以在 MIUI 设备上试用该应用程序,并且通知会正确显示。在 android stock 而不是(例如模拟器)上,这些未显示。我确定通知已到达设备,因为显示通知的函数已调用,但未显示任何内容。你能帮帮我吗?

谢谢!

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);

}

已解决。我想在管理器上添加通知渠道。

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "CHAT_CHANNEL", importance);
        channel.setDescription("NOTIFICATION CHANNEL CHAT");
     
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }