NotificationChannel是android8.0新增的特性,如果App的targetSDKVersion>=26,没有设置channel通知渠道的话,就会导致通知无法展示。
Android O 引入了 通知渠道(Notification Channels),以提供统一的系统来帮助用户管理通知,如果是针对 android O 为目标平台时,必须实现一个或者多个通知渠道,以向用户显示通知。比如聊天软件,为每个聊天组设置一个通知渠道,指定特定声音、灯光等配置。
String channelID = "1"; String channelName = "channel_name"; NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.createNotificationChannel(channel); Notification.Builder builder =new Notification.Builder(context); builder.setContentText(msgDesc); builder.setContentTitle(msgTitle);
本文介绍了Android 8.0中新增的通知渠道(NotificationChannel)特性。为了确保应用能在Android O上正常显示通知,开发者需要为不同类型的推送消息创建相应的通知渠道,并设置其优先级、声音等属性。
3304

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



