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");
我使用此代码创建了一个组,但遗憾的是,没有创建任何人可以帮助我解决这个问题
答案 0 :(得分:0)
这就是我的方法,并且有效:
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.
请注意,通知组(通知组,以前称为捆绑通知)与通知渠道组之间是有区别的。