android - 通知组在没有摘要的情况下无法工作

标签 android android-notifications

我正在实现通知并希望将它们分组以显示在通知栏中。

目前我正在实现 Create a Group of Notifications 中的示例在 Android 的官方开发者文档中。

我实现了这个方法:

private void makeNotification()
{
    createNotificationChannel();

    int SUMMARY_ID = 0;
    String GROUP_KEY_WORK_EMAIL = "com.android.example.WORK_EMAIL";
    String CHANNEL_ID = "MY_CHANNEL_ID";

    Notification newMessageNotification1 =
            new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
                    .setSmallIcon(R.drawable.ic_map_position_icon)
                    .setContentTitle("First summary")
                    .setContentText("You will not believe...")
                    .setGroup(GROUP_KEY_WORK_EMAIL)
                    .build();

    Notification newMessageNotification2 =
            new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
                    .setSmallIcon(R.drawable.ic_map_nav_position_icon_grey)
                    .setContentTitle("Second summary")
                    .setContentText("Please join us to celebrate the...")
                    .setGroup(GROUP_KEY_WORK_EMAIL)
                    .build();

    Notification summaryNotification =
            new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
                    .setContentTitle("Total summary")
                    .setContentText("Two new messages")
                    .setSmallIcon(R.drawable.ic_wdw_dont_drive)
                    .setGroup(GROUP_KEY_WORK_EMAIL)
                    .setGroupSummary(true)
                    .build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    notificationManager.notify(1, newMessageNotification1);
    notificationManager.notify(2, newMessageNotification2);
    notificationManager.notify(SUMMARY_ID, summaryNotification);
}

方法createNotificationChannel()只是创建 channel ,为了更好的可读性,我把它留在这里。

现在文档说:

On Android 7.0 (API level 24) and higher, the system automatically builds a summary for your group using snippets of text from each notification.



所以最后notify()调用应该是可选的,并创建 summaryNotification , 也。但是这个例子只在我通知摘要通知时对我有效。当我不这样做时,通知不会分组。

这里出了什么问题?

最佳答案

On Android 7.0 (API level 24) and higher, the system automatically builds a summary for your group using snippets of text from each notification.



“摘要 [文本]”,但不是“组摘要通知”。这只是意味着您在摘要通知样式中设置的任何文本都将被 Android >= N 的分组通知中的组合文本替换。

这不会影响通知不分组而没有摘要的事实。

是的,这对我也有很大的误导性,必须努力学习。尝试在 Kitkat 上建立组并将其与 Nougat 组进行比较。

关于android - 通知组在没有摘要的情况下无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52497789/

相关文章:

java - 如何根据设备制造商执行不同的代码?

安卓屏幕录像

android - 当应用程序处于后台或关闭时,Android 应用程序中的本地通知不显示

android - 杀死 Activity 的所有实例

android - 在透明背景上的状态栏上永久显示扩展字符串(天气温度),所有字符大小合适且可见

android - 通知声音打断音乐

java - Listview,滚动到底部,EditText View 的奇怪行为

android - moveCamera 和 animateCamera 第二次不起作用

java - RxJava 使用 observables 为 android 构建缓存

android - NavUtils.shouldUpRecreateTask 在 JellyBean 上失败