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