android第一行代码(第二版)第十章serviceBestPractice,日志显示Handler和Looper中有错误

E/AndroidRuntime: FATAL EXCEPTION: main

    Process: com.example.servicebestpractice, PID: 14967

    android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE)

        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1737)

        at android.os.Handler.dispatchMessage(Handler.java:106)

        at android.os.Looper.loop(Looper.java:193)

        at android.app.ActivityThread.main(ActivityThread.java:6669)

        at java.lang.reflect.Method.invoke(Native Method)

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

求大神帮忙解释一下

慕码人5336455
浏览 1522回答 3
3回答

浪里小神龙

原本的NotificationCompat.Builder (Context context)被废弃,在API26之后,创建通知需要使用新的构造器NotificationCompat.Builder (Context context, String channelId)
打开App,查看更多内容
随时随地看视频慕课网APP