Android 8.0以上通知栏不显示
通知栏使用重要的API
NotificationManager
Notification
NotificationChannel
最近在android 8.0的手机上发现通知栏不显示通知了!
No Channel found for pkg=camera.test.com.perssion, channelId=null, id=1, tag=null, opPkg=camera.test.com.perssion,
callingUid=10367, userId=0, incomingUserId=0, notificationUid=10367, notification=Notification(channel=null pri=0
contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE)
android 8.0之后添加了 推送通道,在8.0以上没有设置通道的话就会包上边的错误。可根据8.0以上设置chanle解决问题
Notification notification;
Notification.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder=new Notification.Builder(this,CHANNEL_ID);
}else {
builder=new Notification.Builder(this);
}
builder.setContentTitle("设置标题");
builder.setContentText("内容是............");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setLights(Color.RED, 200, 200);
builder.setSound(Uri.parse("")) ;
builder.setVibrate(new long[]{0, 200, 200, 200, 200, 200});
builder.setAutoCancel(true);
builder.setContentIntent(setPendingIntent("简单通知"));
builder.setPriority(Notification.PRIORITY_HIGH);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(true);
channel.setLightColor(Color.GREEN);
channel.setShowBadge(false);
notificationManager.createNotificationChannel(channel);
}
notification=builder.build();
notificationManager.notify(1,notification);