60、Android开发Notification通知栏( 适配8.0 )

 https://blog.csdn.net/lpcrazyboy/article/details/80756817

 https://blog.csdn.net/guolin_blog/article/details/79854070

final String CHANNEL_ID = "com.chao.channel.id";
final String CHANNEL_NAME = "com.chao.channel.name";

NotificationManager mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = null;


if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
        builder = new NotificationCompat.Builder(this);
}else{
/**
 * Oreo不用Priority了,用importance
 * IMPORTANCE_NONE 关闭通知
 * IMPORTANCE_MIN 开启通知,不会弹出,但没有提示音,状态栏中无显示
 * IMPORTANCE_LOW 开启通知,不会弹出,不发出提示音,状态栏中显示
 * IMPORTANCE_DEFAULT 开启通知,不会弹出,发出提示音,状态栏中显示
 * IMPORTANCE_HIGH 开启通知,会弹出,发出提示音,状态栏中显示
 */
  NotificationChannel notificationChannel = new 
  NotificationChannel(Config.CHANNEL_ID, Config.CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); //如果这里用IMPORTANCE_NOENE就需要在系统的设置里面开启渠道, //通知才能正常弹出  
  mManager.createNotificationChannel(notificationChannel);
  builder = new new NotificationCompat.Builder(this,Config.CHANNEL_ID);
 } 
notification = builder.build();
mManager.notify(555, notification);

 部分机型使用IMPORTANCE_LOW MIN NONE仍然发出提示音问题,修改channelId,可以解决

你可能感兴趣的:(android)