android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false

Viewed 796

I have upgrade the Android SDK project 30 to 31 and I also used permission in manifest: . which is required for targeting SDK 28 and above. In Android 12 I am getting the frequently below crashes on 100% background application. Also, below Android SDK version 30, its working absolutely fine. Thanks in Advance !

Non-fatal Exception: java.lang.RuntimeException: Unable to create service com.UploadService: android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.UploadService
   at android.app.ActivityThread.handleCreateService(ActivityThread.java:4949)
   at android.app.ActivityThread.access$1900(ActivityThread.java:310)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2296)
   at android.os.Handler.dispatchMessage(Handler.java:106)
   at android.os.Looper.loopOnce(Looper.java:226)
   at android.os.Looper.loop(Looper.java:313)
   at android.app.ActivityThread.main(ActivityThread.java:8633)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

I have used work manager for startForegroundService in my code, how to use workmanager for startForeground to restrict this crash in Android12 and above Thanks in advance

0 Answers
Related