Android Question App or a library it uses tried to start a foreground service without declaring a service type

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

I have the app that uses FCM and it works fine, I updated the Firebase settings to enable V1, and followed all the other items in Erel's manual. I can push the messages from my ASP.NET code and receive them on all my devices (Android 10,11,14). I'm using SDK 34, added permissions into my manifest. So far so good.

Here is my manifest

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="34"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:usesCleartextTraffic, "true")
SetApplicationAttribute(android:allowBackup, "false")
CreateResourceFromFile(Macro, Themes.LightTheme)
'Non-SSL permission
CreateResourceFromFile(Macro, Core.NetworkClearText)
'End of default text.

'AddPermission (android.permission.WRITE_EXTERNAL_STORAGE)
'AddPermission (android.permission.READ_EXTERNAL_STORAGE)

'    FusedLocationProvider:

'    required manifest entry required for Google Play Services
AddApplicationText(<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />)
    SetActivityAttribute(MessageDetails, android:windowSoftInputMode, adjustPan|stateHidden)
'Farebase
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, FirebaseAnalytics.Crashlytics)

AddPermission(com.google.android.gms.permission.AD_ID)


'34
AddPermission(android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING)
SetServiceAttribute(FirebaseMessaging, android:foregroundServiceType, "remoteMessaging")

The problem is that on Samsung gta7lite (Galaxy Tab A7 Lite) it crashes with this error


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:8913)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:608)
  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.starter.handleStart (starter.java:105)
  at alex.HCMS.EVV.starter.access$000 (starter.java:11)
  at alex.HCMS.EVV.starter$1.run (starter.java:77)
  at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand (ServiceHelper.java:240)
  at alex.HCMS.EVV.starter.onStartCommand (starter.java:75)
  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:7214)
  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)

You can see in my manifest that I added these permissions. I tested my code on my Android 14 device Samsung S23+ and it works fine when the app in foreground or in background or is not running at all.
What could be a cause of this error? So far it's only 1 device out of 107.

Thanks.
 

Alex_197

Well-Known Member
Licensed User
Longtime User
1. Test it with the B4J sending tool.
2. Have you switched from a service to a receiver for the push interception?
1. Tested it with B4J Sending tool - so far so good.
2. I know that I need to switch to Receiver from Service. Didn't switch yet.

I don't have this Samsung device so I can't test it. But all my own devices are Ok as well as actual users 106 other devices
 
Upvote 0
Top