问题描述
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));
}
有没有兴趣加个微信一起探讨探讨,我也在研究这个问题。