应用程序中创建通知渠道(Notification Channel)的步骤:
1.通过构造方法NotificationChannel(channelId, channelName, importance)创建一个NotificationChannel对象
2.通过createNotificationChannel ( )来注册NotificationChannel一个对象
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = “some_channel_id”;
CharSequence channelName = “Some Channel”;
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
notificationManager.createNotificationChannel(notificationChannel);
创建通知渠道需要三个参数
- channel