gpt4 book ai didi

Android:分组通知和摘要在 4.4 及以下版本仍单独显示

转载 作者:IT王子 更新时间:2023-10-29 00:09:50 24 4
gpt4 key购买 nike

我想实现 stacked notifications on Android Wear 为此,我为每个“项目”创建 1 个摘要通知和 N 个单独的通知。我只想在手机上显示摘要。这是我的代码:

private void showNotifications() {
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
showNotification1(notificationManager);
showNotification2(notificationManager);
showGroupSummaryNotification(notificationManager);
}

private void showNotification1(NotificationManager notificationManager) {
showSingleNotification(notificationManager, "title 1", "message 1", 1);
}

private void showNotification2(NotificationManager notificationManager) {
showSingleNotification(notificationManager, "title 2", "message 2", 2);
}

protected void showSingleNotification(NotificationManager notificationManager,
String title,
String message,
int notificationId) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(title)
.setContentText(message)
.setSmallIcon(R.mipmap.ic_launcher)
.setGroupSummary(false)
.setGroup("group");
Notification notification = builder.build();
notificationManager.notify(notificationId, notification);
}

private void showGroupSummaryNotification(NotificationManager notificationManager) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle("Dummy content title")
.setContentText("Dummy content text")
.setStyle(new NotificationCompat.InboxStyle()
.addLine("Line 1")
.addLine("Line 2")
.setSummaryText("Inbox summary text")
.setBigContentTitle("Big content title"))
.setNumber(2)
.setSmallIcon(R.mipmap.ic_launcher)
.setCategory(Notification.CATEGORY_EVENT)
.setGroupSummary(true)
.setGroup("group");
Notification notification = builder.build();
notificationManager.notify(123456, notification);
}

这在 Android 5.1 上运行良好,只有摘要显示在手机的通知栏中:

enter image description here

但在 Android 4.4 上,它还显示单独的通知 1 和 2:

enter image description here

在这两种情况下,Android Wear 上的通知都会根据需要显示在堆栈中。如何让 Android 4.4 只在通知栏中显示摘要通知?

最佳答案

通过使用解决了这个问题

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

而不是

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

并在相应的方法签名中将 NotificationManager 替换为 NotificationManagerCompat。

关于Android:分组通知和摘要在 4.4 及以下版本仍单独显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31483772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com