Android Question Problems running firebase Push Example

ernschd

Active Member
Licensed User
Longtime User
Hello,


I wanted to try out Firebase for push notifications. That's why I created a new project in Firebase.
After opening the sample project in B4A I get the error:

B4X:
B4XMainPage - 51: Unknown member: permission_post_notifications
The recommended value for android:targetSdkVersion is 30 or higher (Manifesteditor). (warning #31)

Since my Target Sdk version is currently under 30, I have commented out the Permission Part.
This allows the project to be compiled. Unfortunately, I get an error message again when I start it:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
firebasemessaginggetObject (java line: 11)
java.lang.RuntimeException: Code module does not support this method.
    at bfw.testprojekt.firebasemessaging.getObject(firebasemessaging.java:11)
    at bfw.testprojekt.b4xmainpage$ResumableSub_B4XPage_Created.resume(b4xmainpage.java:66)
    at bfw.testprojekt.b4xmainpage._b4xpage_created(b4xmainpage.java:37)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1085)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1040)
    at bfw.testprojekt.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:529)
    at bfw.testprojekt.b4xpagesmanager._showpage(b4xpagesmanager.java:866)
    at bfw.testprojekt.b4xpagesmanager._addpage(b4xpagesmanager.java:200)
    at bfw.testprojekt.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:207)
    at bfw.testprojekt.b4xpagesmanager._initialize(b4xpagesmanager.java:717)
    at bfw.testprojekt.main._activity_create(main.java:366)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at bfw.testprojekt.main.afterFirstLayout(main.java:105)
    at bfw.testprojekt.main.access$000(main.java:17)
    at bfw.testprojekt.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:211)
    at android.os.Looper.loop(Looper.java:300)
    at android.app.ActivityThread.main(ActivityThread.java:8295)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:577)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1074)

The error is thrown when calling
B4X:
CallSubDelayed2(FirebaseMessaging, "SubscribeToTopics", Array("general"))

I replaced the code module with a service module as a test and was able to start the app without any problems.
However, the notifications from the B4J sending tool do not arrive - but the job result is "Success". The notifications via the Firebase console arrive.

Is this perhaps due to the B4X version 11.80? Unfortunately I cannot update (see my post here).

Thank you in advance.
 

DonManfred

Expert
Licensed User
Longtime User
The code module was in the example project.

There is no codemodule in the Example. The module inside the B4A example is a Receiver-Module

Type=Receiver

B4X:
B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Receiver
Version=12.5
@EndOfDesignText@
Sub Process_Globals
    Private fm As FirebaseMessaging
End Sub

Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
    If FirstTime Then
        fm.Initialize("fm")
    End If
    fm.HandleIntent(StartingIntent)
End Sub

Public Sub SubscribeToTopics (Topics() As Object)
    For Each topic As String In Topics
        fm.SubscribeToTopic(topic)
    Next
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    If B4XPages.IsInitialized And B4XPages.GetManager.IsForeground Then
        Log("App is in the foreground. In iOS a notification will not appear while the app is in the foreground (unless UserNotificationCenter is used).")
    End If
    Dim n2 As Notification
    n2.Initialize2(n2.IMPORTANCE_HIGH)
    n2.Icon = "icon"
    n2.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    n2.Notify(1)
End Sub

Sub fm_TokenRefresh (Token As String)
    Log("TokenRefresh: " & Token)
End Sub
 
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
Ok, I have just seen that receivers have been introduced with B4A v12.2.
I am using 11.80 as I cannot update because of my existing project. There the module is opened as a code module.
Shouldn't reception via the B4J transmission tool still work (with a service instead of a receiver)?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I am using 11.80 as I cannot update because of my existing project
Yes, receivers are new. They have replaced the old service in the newest SDK.

as you are most probably using the old SDK and old B4A you need to implement FirebaseMessaging as a Service like it was in the past.
 
Last edited:
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
Does anyone have any idea why the notifications from the B4J send tool are not arriving and the notifications from the Firebase console are? Can I display a log somewhere in Firebase?
 
Upvote 0
Top