I have an app that uses a sticky foreground service to do some Bluetooth operations, it was working well untill android 14 release.
I got this trace from Firebase although I am not able to reproduce.
Caused by android.app.ForegroundServiceStartNotAllowedException
Service.startForeground() not allowed due to mAllowStartForeground false: service xx.xxx.ForegroundService
android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:54)
android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:50)
android.os.Parcel.readParcelableInternal (Parcel.java:4882)
android.os.Parcel.readParcelable (Parcel.java:4864)
android.os.Parcel.createExceptionOrNull (Parcel.java:3064)
android.os.Parcel.createException (Parcel.java:3053)
android.os.Parcel.readException (Parcel.java:3036)
android.os.Parcel.readException (Parcel.java:2978)
android.app.IActivityManager$Stub$Proxy.setServiceForeground (IActivityManager.java:7214)
android.app.Service.startForeground (Service.java:775)
xx.xxx.ForegroundService.onStartCommand (ForegroundService.kt:57)
android.app.ActivityThread.handleServiceArgs (ActivityThread.java:5268)
android.app.ActivityThread.-$$Nest$mhandleServiceArgs
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2531)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loopOnce (Looper.java:230)
android.os.Looper.loop (Looper.java:319)
android.app.ActivityThread.main (ActivityThread.java:8893)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:608)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103)
I have updated my app to meet android 14 service requirements, but the crash still persist.
Also as I am aware, this is not the error mentioned in the documentation when not meeting android 14 foreground service requirements.
I have found this issue: https://issuetracker.google.com/issues/307329994
Any help would be appreciated!
START_NOT_STICKY
will resolve the problem. However it's not a good option for us, because we need the service to be sticky. – Claar