Android Question Firebase push notifications not working on B4A 9.01.2 ?

Discussion in 'Android Questions' started by eXcedi, Jul 7, 2019.

  1. eXcedi

    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)
     
  2. soyVB6

    soyVB6 Active Member Licensed User

    Hello
    I think the small error is in the s at the end of the function


    Code:
    'subscribeToTopic
    Public Sub SubscribeToTopics(topic As String)
    fm.SubscribeToTopic(topic) 
    'you can subscribe to more topics
    End Sub
     
  3. eXcedi

    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)
     
  4. soyVB6

    soyVB6 Active Member Licensed User

  5. Erel

    Erel Administrator Staff Member Licensed User

    Moved to the questions forum.
     
    soyVB6 likes this.
  6. eXcedi

    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
     
  7. DonManfred

    DonManfred Expert Licensed User

    upload the new testproject to see how you have implemented it.
     
  8. eXcedi

    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)
     
  9. DonManfred

    DonManfred Expert Licensed User

    1. Use code tags when posting code.
    2. I asked you to upload the project. In the IDE: Use File->Export as zip. Upload this zip.
     
    eXcedi likes this.
  10. eXcedi

    eXcedi Member Licensed User

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

    Attached Files:

  11. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Public Sub SubscribeToTopics(Topic As String)
    You are calling it with:
    Code:
    CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
    The Topic parameter is missing. You should use CallSubDelayed2.
     
    peacemaker likes this.
  12. eXcedi

    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
     
  13. DonManfred

    DonManfred Expert Licensed User

    You can find the Setup-Instructions here. https://www.b4x.com/b4a.html
    You also can watch this Video as it describes it clearly.


    Start with a new Blank folder like you see in the Video.

    Make sure to use Android.jar from Platform 28.
     
    soyVB6 and Johan Hormaza like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice