java - 如何创建通知 channel 组?

标签 java android

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String channel_Id = "Daily";
    CharSequence name = "Daily";
    String description = "Get Notifications about today's rupee changes";
    int importance = NotificationManager.IMPORTANCE_HIGH;
    NotificationChannel channel = new NotificationChannel(channel_Id,name,importance);
    channel.setDescription(description);
    channel.enableLights(true);
    channel.setLightColor(Color.RED);
    channel.enableVibration(true);
    channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
    notificationManager.createNotificationChannel(channel);
    String group = "Daily_group";
    CharSequence group_name = "Daily Notifications";
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup(group,group_name));
    channel.setGroup("Daily_group");
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this, channel_Id)
                    .setSmallIcon(R.mipmap.ic_launcher_round)
                    .setContentTitle("My notification")
                    .setContentText("Hello World!").setGroup("Daily_group");


    notificationManager.notify(123,mBuilder.build());
    Log.d(tag,"Done");

我用这段代码创建了一个组,但遗憾的是没有创建组,任何人都可以帮助我解决这个问题

最佳答案

这就是我的工作方式:

NotificationManager notificationManager =getSystemService(NotificationManager.class);

NotificationChannelGroup notificationChannelGroup=
         new  NotificationChannelGroup(GROUP_ID, 
                                 getApplicationContext().getString(R.string.GROUP_NAME));
notificationManager.createNotificationChannelGroup(notificationChannelGroup);

可以在此处找到有关组的更多阅读:channels Notif. Groups Group of notif.

注意通知组(Group of Notifications,以前叫Bundled notifications)和Notification Channel Group是有区别的。混淆...

关于java - 如何创建通知 channel 组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48790779/

相关文章:

java - 动态更改模拟对象返回值

android - FragmentStatePagerAdapter 是否在方向更改时保存 fragment 状态?

Java 制作类的数组列表并调用该类的方法

java - 自定义对象数组和 For 循环

java - Android Studio 未知类

java - 尝试使用 getChildAt() 取消选择 View

java - 安卓 AES 问题

Java:当对象在初始化 block 中初始化时,从另一个类调用对象的方法

android - 设置 Android 对话框位置

java - AndEngine 的 GenericPool 处理 6 个 Sprite