Android Question Firebase push notifications not working on B4A 9.01.2 ?

eXcedi

Member
Licensed User
I get this error message when i run my firebase related app. Any help??

Logger connected to: Infinix Infinix-X600
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
firebasemessaging_subscribetotopics (java line: 237)
java.lang.NoSuchMethodError: No virtual method subscribeToTopic(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/messaging/FirebaseMessaging; or its super classes (declaration of 'com.google.firebase.messaging.FirebaseMessaging' appears in /data/app/com.tedgeapp.tarragonedge-1/base.apk)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at com.tedgeapp.tarragonedge.firebasemessaging._subscribetotopics(firebasemessaging.java:237)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
firebasemessaging_subscribetotopics (java line: 237)
java.lang.NoSuchMethodError: No virtual method subscribeToTopic(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/messaging/FirebaseMessaging; or its super classes (declaration of 'com.google.firebase.messaging.FirebaseMessaging' appears in /data/app/com.tedgeapp.tarragonedge-2/base.apk)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at com.tedgeapp.tarragonedge.firebasemessaging._subscribetotopics(firebasemessaging.java:237)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
 

Duque

Active Member
Licensed User
Longtime User
Hello
I think the small error is in the s at the end of the function


B4X:
           'subscribeToTopic
Public Sub SubscribeToTopics(topic As String)
fm.SubscribeToTopic(topic) 'you can subscribe to more topics
End Sub
 
Upvote 0

eXcedi

Member
Licensed User
thanks for the heads up. after the update the error has now become this

i hope i am not being a bother but i am really starting to enjoy B4A

Logger connected to: Infinix Infinix-X600
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
java.lang.Exception: Sub subscribetotopics signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:198)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
 
Upvote 0

eXcedi

Member
Licensed User
Is it possible to have a some woking code in the form of a project (b4A 9.01.2)
i might be missing something becasue i have followed all the steps in the tutorial.

initially i was trying to add push notifications to an existing project.

i have now created a new project from scratch and the problem still persists
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i have now created a new project from scratch and the problem still persists
upload the new testproject to see how you have implemented it.
 
Upvote 0

eXcedi

Member
Licensed User
FirebaseMessaging Service

#Region Service Attributes
#StartAtBoot: False

#End Region
Sub Process_Globals
Private fm As FirebaseMessaging
End Sub

Sub Service_Create
fm.Initialize("fm")
End Sub

Public Sub SubscribeToTopics(Topic As String)
fm.SubscribeToTopic("general") 'you can subscribe to more topics
End Sub

Sub Service_Start (StartingIntent As Intent)
If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
Sleep(0)
Service.StopAutomaticForeground 'remove if not using B4A v8+.
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
Log($"Message data: ${Message.GetData}"$)
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
n.Notify(1)
End Sub

Sub Service_Destroy

End Sub






Starter Service

#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End Sub

Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub

Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub

Sub Service_Destroy

End Sub


Manifest Editor

'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="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
 
Upvote 0

eXcedi

Member
Licensed User
thanks for showing me to...i have named the exported project as "exported"
 

Attachments

  • exported.zip
    9.4 KB · Views: 387
Upvote 0

eXcedi

Member
Licensed User
whew!... i'm getting frustrated....

i am still trying to resolve the firebase issue and now this is what i get when compiling

Generating R file. Error
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex

Please help me out
 
Upvote 0
Top