一、这是之前的代码
public void onClick(View view) {
switch (view.getId()){
case R.id.send_notice:
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("这是通知标题")
.setContentText("这是通知内容")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.build();
manager.notify(1,notification);
break;
default:
break;
}
}
在安卓8.0之前的版本运行结果:发现可以运行
在8.0及以上版本运行:发现没有显示通知,
输出一条信息:D/skia: --- Failed to create image decoder with message 'unimplemented'
下面是经过修改后代码
public void onClick(View view) {
switch (view.getId()){
case R.id.send_notice:
NotificationChannel notificationChannel = null;
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
notificationChannel = new NotificationChannel("001", "channel_name", NotificationManager.IMPORTANCE_LOW);
manager.createNotificationChannel(notificationChannel);
}
Notification notification = new NotificationCompat.Builder(this,"001")
.setContentTitle("这是通知标题")
.setContentText("这是通知内容")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.build();
manager.notify(1,notification);
break;
default:
break;
}
}
运行后发现可以推送通知了,但是依然输出D/skia: --- Failed to create image decoder with message 'unimplemented' 不知道咋回事
小米手机有个通知过滤功能,开启之后会自动收纳不重要的通知,搞了半天以为代码问题