第一行代码前台服务出错记录FATAL EXCEPTION: main Process: com.android.systemui
照着第一行代码敲项目时出现如下错误
解决方法:
notification = new NotificationCompat.Builder(this, channelId)
.setContentTitle("this is content title")
.setContentText("this is content text")
.setWhen(System.currentTimeMillis())
.setShowWhen(true)
// .setSmallIcon(R.mipmap.ic_launcher)
.setSmallIcon(R.drawable.ic_launcher_background)// 用R.mipmap.ic_launcher会报错SystemUI问题
.setContentIntent(pi)
.build();
将setSmallIcon(R.mipmap.ic_launcher)
改为.setSmallIcon(R.drawable.ic_launcher_background)
有关于前台服务和notification在android8.0的变更可以参考以下链接:https://blog.****.net/o279642707/article/details/82352431
https://blog.****.net/qq_40909351/article/details/84986330