gpt4 book ai didi

java - 如何创建通知 channel 组?

转载 作者:行者123 更新时间:2023-11-30 00:07:01 30 4
gpt4 key购买 nike

    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/

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