关于Android通知Notification 8.0之后版本不能推送问题

一、这是之前的代码

 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' 不知道咋回事

小米手机有个通知过滤功能,开启之后会自动收纳不重要的通知,搞了半天以为代码问题

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值