Android Question A question about receivers and foregroundServiceStartNotAllowed Exception

tufanv

Expert
Licensed User
Longtime User
Hello,

I am getting this error for a while. I don't have any "startserviceat" or similar. My questions:

1) Should I change starter service to reciever?
2) In my firebase messaging receiver, only sub that can trigger background start is fm_messagearrived sub. Mine is :

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    Dim n2 As Notification
    n2.Initialize2(n2.IMPORTANCE_HIGH)
    n2.Icon = "icon"
    n2.Sound=True
    n2.SetInfo2(Message.GetData.Get("title"), Message.GetData.Get("body"),Message.GetData.Get("ilgili"), Main)
    n2.Notify(1)
    Main.notitite=Message.GetData.Get("title")
    Main.notitext=Message.GetData.Get("body")
    If Main.isactive Then
        CallSub(Main, "notiac")
    End If
  
End Sub

What can cause the foregroundServiceStartNotAllowed Exception here? callsub to a main? Or the error is coming from somewhere else?

My starter service has:

B4X:
Sub Service_Start (StartingIntent As Intent)

    Service.StopAutomaticForeground 'remove if not using B4A v8+.

End Sub

this can cause it?
 

tufanv

Expert
Licensed User
Longtime User
sure:
Please post the full error message / stack trace.
B4X:
Fatal Exception: java.lang.RuntimeException
android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service ct.canlidoviz/.httputils2service
anywheresoftware.b4a.keywords.Common$12.run (Common.java:1215)

com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)

Caused by android.app.ForegroundServiceStartNotAllowedException
startForegroundService() not allowed due to mAllowStartForeground false: service ct.canlidoviz/.httputils2service
android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:54)
android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:50)
android.os.Parcel.readParcelable (Parcel.java:3346)
android.os.Parcel.createExceptionOrNull (Parcel.java:2433)
android.os.Parcel.createException (Parcel.java:2422)
android.os.Parcel.readException (Parcel.java:2405)
android.os.Parcel.readException (Parcel.java:2347)
android.app.IActivityManager$Stub$Proxy.startService (IActivityManager.java:6969)
android.app.ContextImpl.startServiceCommon (ContextImpl.java:1927)
android.app.ContextImpl.startForegroundService (ContextImpl.java:1893)
android.content.ContextWrapper.startForegroundService (ContextWrapper.java:798)
anywheresoftware.b4a.keywords.Common.StartServiceImpl (Common.java:924)
anywheresoftware.b4a.keywords.Common.StartService (Common.java:911)
anywheresoftware.b4a.keywords.Common$12.run (Common.java:1183)
android.os.Handler.handleCallback (Handler.java:938)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loopOnce (Looper.java:226)
android.os.Looper.loop (Looper.java:313)
android.app.ActivityThread.main (ActivityThread.java:8669)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)

Caused by android.os.RemoteException
Remote stack trace: at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:771) at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:679) at com.android.server.am.ActivityManagerService.startService(ActivityManagerService.java:14102) at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2960) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3034)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need to update OkHttpUtils2.

 
Upvote 0
Top