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);
创建通知渠道需要三个参数
- channelId 通知渠道的ID 可以是任意的字符串,全局唯一就可以
- channelName 通知渠道的名称,这个是用户可见的,开发者需要认真规划的命名
- importance 通知渠道的重要等级,有一下几个等级,不过这个用户都是可以手动修改的

其次我们可以通过使用通知渠道提供给我们的一些公共方法来操纵该通知渠道:
- getId()—检索给定通道的ID
- enablellights()

最低0.47元/天 解锁文章
285

被折叠的 条评论
为什么被折叠?



