Android 8.0 通知适配问题

Android O 对通知部分进行了调整。致使通知在android O上没法展现。android

1,新的重要特性:NotificationChannel ui

1)在发送通知消息前须要建立notification chanel。 chanel 建立一次便可。 没必要每次发送通知前都建立。get

String channelId:建议使用包名拼接io

String chanelNamechannel

NotificationChannel mChannel = new NotificationChannel(channelId, chanelName, NotificationManager.IMPORTANCE_LOW);
mChannel.enableLights(true);//开启灯光
mChannel.setLightColor(Color.RED);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(mChannel);

2)建立notification:  对于android O , 须要在builder 中设置chanel ID , 对应于以前建立 的chanel id 。notification

NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);
      if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
         mBuilder.setChannelId(PushMessageService.CHANEL_ID_S);
      }

 

2,android O 上聚合的通知消息。vi

当有多条通知消息到达的时候。 同一个chanel id 的通知消息是聚合展现在一个条目下面的。 此时下滑即所有展开。co

相关文章
相关标签/搜索