Android 开发 之 8.0 Notification

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/z_x_Qiang/article/details/80565919

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);


猜你喜欢

转载自blog.csdn.net/z_x_Qiang/article/details/80565919