android startForegroundService ,调用startForeground还是报错

问题描述

android startForegroundService ,调用了startForeground还是报同样错

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

        if (Build.VERSION.SDK_INT >= 26) {
            this.startForegroundService(new Intent(this, TestService.class));

            NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            NotificationChannel Channel = new NotificationChannel("bxforeground", "啦啦啦", NotificationManager.IMPORTANCE_HIGH);
            Channel.enableLights(true);//设置提示灯
            Channel.setLightColor(Color.RED);//设置提示灯颜色
            Channel.setShowBadge(true);//显示logo
            Channel.setDescription("啦啦啦");//设置描述
            Channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); //设置锁屏可见 VISIBILITY_PUBLIC=可见
            manager.createNotificationChannel(Channel);
            Notification notification = new Notification.Builder(this)
                    .setChannelId("bxforeground")
                    .setContentTitle("啦啦啦")
                    .setContentText("啦啦啦")
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                    .build();
            startForeground(102, notification);

        } else {
            this.startService(new Intent(JobWakeService.this, TestService.class));
        }

你期待的结果是什么?实际看到的错误信息又是什么?

clipboard.png

阅读 5.8k
2 个回答
新手上路,请多包涵

有没有兴趣加个微信一起探讨探讨,我也在研究这个问题。

新手上路,请多包涵

请问问题解决了么

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题