如何在Oreo开始通知中更改“类别”?

时间:2018-11-12 13:01:19

标签: android push-notification android-8.0-oreo

下面是Facebook应用程序的“设置”屏幕。在我的应用程序中,它显示“类别”,这里是“ Kalis Martinez”。我想在我的应用中实现这一目标。

enter image description here

我的应用程序显示的内容如下:

enter image description here

我正在做的事情如下。

NotificationManager manager = (NotificationManager) 
getSystemService(Context.NOTIFICATION_SERVICE);
        manager.createNotificationChannelGroup(new 
NotificationChannelGroup(groupId, groupName));

String GROUP_KEY_WORK_EMAIL = "com.android.example.WORK_EMAIL";

    Notification notification = new Notification.Builder(getApplicationContext(), SECONDARY_CHANNEL)
            .setContentTitle(title)
            .setContentText(body)
            //build summary info into InboxStyle template
            .setStyle(new Notification.InboxStyle()
                    .addLine("Alex Faarborg  Check this out")
                    .addLine("Jeff Chang    Launch Party")
                    .setBigContentTitle("2 new messages")
                    .setSummaryText("janedoe@example.com"))
            //specify which group this notification belongs to
            .setGroup(GROUP_KEY_WORK_EMAIL)
            //set this notification as the summary for the group
            .setGroupSummary(true)
            .setSmallIcon(getSmallIcon())
            .setAutoCancel(true);

manager.notify(id, notification.build());

setGroup()setGroupSummary()在系统托盘中显示通知时进行分组。

如何更改标签?

1 个答案:

答案 0 :(得分:0)

使用它来创建一个通知组,以更改标题,例如

// The id of the group.
String groupId = "my_group_01";
// The user-visible name of the group.
CharSequence groupName = getString(R.string.group_name);
NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(groupId, groupName));

或查看有关Notification Channels