【发布时间】:2021-02-23 16:07:58
【问题描述】:
我正在我的应用程序上实现推送通知。不幸的是,在实现它们之后,这些不会在某些设备上显示。一般来说,我可以在 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);
}
【问题讨论】:
标签: java firebase android-studio push-notification notifications