android 4.4 通知显示,Android:分组通知和摘要仍然分别显示在4.4和以下

Android:分组通知和摘要仍然分别显示在4.4和以下

我想在Android Wear上实施堆叠通知为此,我为每个“商品”创build了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上运行得很好,只有摘要显示在手机的通知栏中:

edd03e6dc4ef9f72f1aec91bb9101dd2.png

但在Android 4.4上,它也显示了个人通知1和2:

sSQsE.png

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

通过使用固定这个

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

代替

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

并用相应方法签名中的NotificationManagerCompatreplaceNotificationManager。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值