小编geo*_*667的帖子

android 13 startForeground 的错误通知

每次执行应用程序时,我都会收到“startForeground 的错误通知”错误

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.pennskanvtic, PID: 17447
    android.app.RemoteServiceException$CannotPostForegroundServiceNotificationException:
Bad notification for startForeground
        at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:1978)
        at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2237)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7884)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)`
Run Code Online (Sandbox Code Playgroud)

我的服务仅启动计时器并显示通知(我尝试在NotificationCompat.Builder中使用setChannelId而不进行任何更改):

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.pennskanvtic, PID: 17447
    android.app.RemoteServiceException$CannotPostForegroundServiceNotificationException:
Bad notification for startForeground
        at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:1978)
        at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2237)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7884)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)`
Run Code Online (Sandbox Code Playgroud)

我的 MainActivity 在 onStart() 内请求许可:

public class …
Run Code Online (Sandbox Code Playgroud)

java android-notifications android-13

4
推荐指数
1
解决办法
6201
查看次数

标签 统计

android-13 ×1

android-notifications ×1

java ×1