记(Android|记:Android 8.0通知栏显示问题)

在Android最新的版本(8.0)中,通知栏的显示已经不像之前那么简单,必须给Notification添加channel,这是8.0的新特性,如果不加这个channel,会导致通知栏无法显示。代码如下:
NotificationCompat.Builder builder = null;
【记(Android|记:Android 8.0通知栏显示问题)】if(android.os.Builde.VERSION.SDK_INT >= Builder.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL, 'Primary channel', NotificationManager.IMPORTANCE_DEFAULT);
channel.setLightColor(Color.GREEN);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationManager.createNotificationChannel(channel);
builder = new NotificationCompat.Builder(context, PRIMARY_CHANNEL);
}

    推荐阅读