Android Question java.lang.RuntimeException: android.app.MissingForegroundServiceTypeException: Starting FGS without a type

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

I received an email from the Crashlytics.

My app is setup for targetSDK 34.

This is what happened - in my app I'm using Firebug messaging system. I read in Erel tutorial that I need to add 2 lines into my manifest and specify a ForegroundServiceType.

What type to specify for Firebug messaging system? Should it be remoteMessaging? Description of this type shows this
B4X:
Transfer text messages from one device to another. Assists with continuity of a user's messaging tasks when they switch devices.

Here is an error log form the Crashlitycs.

B4X:
          Fatal Exception: java.lang.RuntimeException: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{82af9ba 26943:alex.HCMS.EVV/u0a532} targetSDK=34
       at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.handleStartIntent(ServiceHelper.java:173)
       at alex.HCMS.EVV.firebasemessaging.handleStart(firebasemessaging.java:102)
       at alex.HCMS.EVV.firebasemessaging.access$000(firebasemessaging.java:8)
       at alex.HCMS.EVV.firebasemessaging$2.run(firebasemessaging.java:83)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8919)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

I installed a copy of my app from the Google Play market and tested it on my Samsung S23+ with Android 14 and it. What I've notice last night when my phone was in Do Not Disturbe mode that if I sent a message to my phone it pops up a small window with 2 questions
Close the App?
Wait

Sent a new message again at 2:30 AM - message icon comes up.

Sent a new message agan in about 9 AM - works fine - icon and beep. Could it be just a coinsedence?
My app is not B4XPages and I'm using Service but not Receiver.

Thanks.
 

Alex_197

Well-Known Member
Licensed User
Longtime User
Thank you, Erel for your reply. I read this tutorial and I want to know what type to apply for Firebug messaging system?

Because the error shows this - alex.HCMS.EVV.firebasemessaging.handleStart
B4X:
Exception java.lang.RuntimeException:
  at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:5286)
  at android.app.ActivityThread.-$$Nest$mhandleServiceArgs
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2531)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loopOnce (Looper.java:230)
  at android.os.Looper.loop (Looper.java:319)
  at android.app.ActivityThread.main (ActivityThread.java:8919)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:578)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103)
Caused by java.lang.RuntimeException:
  at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.handleStartIntent (ServiceHelper.java:173)
  at alex.HCMS.EVV.firebasemessaging.handleStart (firebasemessaging.java:102)
  at alex.HCMS.EVV.firebasemessaging.access$000 (firebasemessaging.java:8)
  at alex.HCMS.EVV.firebasemessaging$1.run (firebasemessaging.java:74)
  at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand (ServiceHelper.java:240)
  at alex.HCMS.EVV.firebasemessaging.onStartCommand (firebasemessaging.java:72)
  at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:5268)
Caused by android.app.MissingForegroundServiceTypeException:
  at android.app.MissingForegroundServiceTypeException$1.createFromParcel (MissingForegroundServiceTypeException.java:53)
  at android.app.MissingForegroundServiceTypeException$1.createFromParcel (MissingForegroundServiceTypeException.java:49)
  at android.os.Parcel.readParcelableInternal (Parcel.java:4882)
  at android.os.Parcel.readParcelable (Parcel.java:4864)
  at android.os.Parcel.createExceptionOrNull (Parcel.java:3064)
  at android.os.Parcel.createException (Parcel.java:3053)
  at android.os.Parcel.readException (Parcel.java:3036)
  at android.os.Parcel.readException (Parcel.java:2978)
  at android.app.IActivityManager$Stub$Proxy.setServiceForeground (IActivityManager.java:7234)
  at android.app.Service.startForeground (Service.java:775)
  at anywheresoftware.b4a.objects.ServiceHelper.StartForeground (ServiceHelper.java:85)
  at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.handleStartIntent (ServiceHelper.java:171)
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
You need to go over the available types and decide which one is most suitable: https://developer.android.com/about/versions/14/changes/fgs-types-required
I will - the problem is that this Firebug messaging system works on my Android 14 phone.

I've noticed this.

Phone is "sleeping" at night.
Do Not Disturbe is On.
I sent a message.
Woke up my phone.
The message icon doesn't show up and no error messages on a screen.

Right after it I sent another message. Message icon appears on a top. No beep because the phone in Do Not Disturbe.


Could it be a cause of the problem?
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
I updated my manifest
B4X:
AddPermission(android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING)
SetServiceAttribute(Starter, android:foregroundServiceType, "remoteMessaging")

and I have compilation error

B4X:
AndroidManifest.xml:178: error: 'remoteMessaging' is incompatible with attribute foregroundServiceType (attr) flags [camera=64, connectedDevice=16, dataSync=1, location=8, mediaPlayback=2, mediaProjection=32, microphone=128, phoneCall=4].
error: failed processing manifest.

Does it mean that I need to use B4A ver.13? Why the remoteMessaging is not on a list?

Thank you.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…