Android Question Exception java.lang.RuntimeException: Unable to start receiver ...firebasemessaging$firebasemessaging_BR

hello Team,

i am using firebase notification library 2.01 and b4a 11.8 , when i was using the sdk 30 everything was working fine but when i started using the sdk 31 its giving me this error in play console:
Exception java.lang.RuntimeException: Unable to start receiver ...firebasemessaging$firebasemessaging_BR
i am sending the notification with high priority and the error is still there.
 
hello Erel,

i downloaded the b4a 12 beta and i updated the sdk , and i used the sdk 33 but the error is still there and i found out that the error is accuring when i receive a message from the firebase messaging when the app is closed (background) , and that is only happening in the sdk 31 & 32 & 33 , but from the sdk 30 and every sdk before that is working fine.

Exception java.lang.RuntimeException: Unable to start receiver com.alilea.firebasemessaging$firebasemessaging_BR: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.alilea/.firebasemessaging
at android.app.ActivityThread.handleReceiver (ActivityThread.java:4852)
at android.app.ActivityThread.access$1700 (ActivityThread.java:315)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2297)
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:8751)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)
Caused by android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.alilea/.firebasemessaging
at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:54)
at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:50)
at android.os.Parcel.readParcelable (Parcel.java:3345)
at android.os.Parcel.createExceptionOrNull (Parcel.java:2432)
at android.os.Parcel.createException (Parcel.java:2421)
at android.os.Parcel.readException (Parcel.java:2404)
at android.os.Parcel.readException (Parcel.java:2346)
at android.app.IActivityManager$Stub$Proxy.startService (IActivityManager.java:6968)
at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1927)
at android.app.ContextImpl.startForegroundService (ContextImpl.java:1893)
at android.content.ContextWrapper.startForegroundService (ContextWrapper.java:798)
at android.content.ContextWrapper.startForegroundService (ContextWrapper.java:798)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.startServiceFromReceiver (ServiceHelper.java:141)
at com.alilea.firebasemessaging$firebasemessaging_BR.onReceive (firebasemessaging.java:17)
at android.app.ActivityThread.handleReceiver (ActivityThread.java:4843)
 
Upvote 0
i downloaded the stable version, below is the b4j code that i am using, but i am using it in b4a not in b4j because i want to send the message from my android phone:
and also sometimes i choose to receive the message without notification, so may that be what is causing the issue?


B4X:
Private Sub SendMessage(Topic As String, Title As String, Body As String)
    Try
        Dim job As HttpJob
        job.Initialize("fcm", Me)
        Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
        Dim data As Map = CreateMap("title": Title, "body": Body)
        If Topic.StartsWith("ios_") Then
            Dim iosalert As Map =  CreateMap("title": Title, "body": Body, "sound": "default")
            m.Put("notification", iosalert)
            m.Put("priority", 10)
        End If
        m.Put("data", data)
        Dim jg As JSONGenerator
        jg.Initialize(m)
        job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
        job.GetRequest.SetContentType("application/json;charset=UTF-8")
        job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
    Catch
    End Try
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
hello,


please note that i am still seeing this error on the play console

Exception java.lang.RuntimeException: Unable to start receiver ...firebasemessaging$firebasemessaging_BR​


i thought it got solved because after i put it on high priority it stopped crashing while i was testing it on the emulator android 12 but i guess it is not solved yet because im still seeing this error in play console.

i will now list a few things that i have written in the firebase messaging service maybe one of them seems to be what is causing this error:

1. i am receiving the message in a string value without notification.
2. i am saving the message in a txt file in the internal storage.
3. i am using call sub for a method in the main activity from the firebasemessaging service accrues if the app is open
4. i am using nb6 to create notification to some of the messages, after they get saved in the txt file inside the internal storage.
5. i am reading the time from the firebasemessaging service

please note that i am using the B4 J code in B4 A application to send the message
 
Upvote 0
hello,
in the new version that i have launched the one that is still getting the error, i unsubscribed the old topic (general) that was being used in low priority, and all the messages are now being sent to topic (general1) in high priority.

i have put in the firebasemessaging service :

fm.UnsubscribeFromTopic("general")
fm.SubscribeToTopic("general1")

if the above code is working correctly i should not have any messages being sent in low priority , so may there be anything i am doing wrong with the above code?
i have 30 thousand users that are being effected with this crash, thats why if i couldnt solve this error may you be able to help with a library that includes something like;

try {
// Block of code to try
}
catch(Exception e) {
// Block of code to handle errors
}

thank you,
 
Upvote 0
thank Erel for your kind assistance,

i noticed that there is many ANRs that started occurring once the error started occurring only on version android 12, & 13.
attached are screenshots that clarify what is happening




Untitled.png
Untitled1.png
Untitled2.png
 
Upvote 0
Even though we had a big loss of users because of this error but thanx god it has now been solved by replacing the "service" with "receiver" in this new version of B4A 12.2
Thank you
 
Upvote 0
Top