Android Question Firebase Notifications are not working

Kevin Hartin

Active Member
Licensed User
I had this working very well on an early version of my App, but since upgrading and changing the Apps name, it seems that Notifications are not working.

I send notifications from a PHP server and have changed the API key to match the new project name. When I send a notification, it seems to work as I get a valid JSON response like {"message_id":8297357908508888637} but nothing happens beyond that.

Similarly when using the B4J non UI sending app I get a seemingly valid response of {"message_id":6194401728449346950} and still I do not get a notification.

I am using exactly the same topics to subscribe on the Android App as well as send on the Java app. I get true when I log fm.IsInitialised before subscribing on the Android App.

Is there any way to check if an App has actually subscribed to a topic other than to receive the Notifications?

Could I be missing a permission in the App?

Does google-services.json come into this? I resurected the old app and it asked about this.

FirebaseMessaging Service:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

Sub Process_Globals
    Private fm As FirebaseMessaging
End Sub

Sub Service_Create
    fm.Initialize("fm")
    Log("fm.isinitialised:"&fm.IsInitialized)
End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("BookingMyTravelSupplier"&Starter.SupplierID) 'you can subscribe to more topics
    Log("Firebase Messaging subscribed to BookingMyTravelSupplier"&Starter.SupplierID)
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}"$)
    CallSubDelayed(Bookings,"syncBookings")
    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

Starter Service:
    Log("Starter FB:"&SupplierID)
    If SupplierID <> "" Then CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")

Manifest:
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
Thanks,
Kev
 
Last edited:

Kevin Hartin

Active Member
Licensed User
B4X:
   #StartAtBoot: True
This is a mistake.

Create a new project with the same package name and follow these instructions: https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/
No need to add anything not mentioned in the tutorial.

Does it work?

It was originally #StartAtBoot: False but had tried #StartAtBoot: True at the time of posting the error

Actually nothing works now. I installed 10.9 Beta and now everything compiles OK, but immediately crashes on load on the device. Nothing on the debug screen.

I have uninstalled 10.9 and reinstalled 10.7, but it is the same. I did run SDK manager in 10.9, but I figure this updates Google stuff and is the same as 10.7. I don't think this is related, but mention it as it seems co-incidental

It seems to only be related to Apps running Firebase (My Main App and a couple of minor Apps) as I tried other samples and apps I have written and they seem OK. I have followed your video twice now and get the same result. apps are attached.

Kev
 

Attachments

  • FBNOTIFY.zip
    19.8 KB · Views: 121
  • non-ui.zip
    1.3 KB · Views: 125
Upvote 0

Kevin Hartin

Active Member
Licensed User
OK, I thought that the description in the 10.9 notes indicates an improved firebase.

How do I remove and reinstall the SDK? Do I lose all updates that take many hours on our slow and expensive 3G?

Kev
 
Upvote 0

Kevin Hartin

Active Member
Licensed User
You can install it in a new folder and configure the IDE to use the new one (android.jar path).
It includes all resources that are usually needed.

I did that and now i get this error on compile;
Compile Error:
Uncaught translation error: com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
I saw your earlier post https://www.b4x.com/android/forum/t...iling-after-latest-sdk-update.130694/#content on a similar issue and tried your suggested fix, but it made no difference. Using the barebones test I built following your video, there is only firebasenotifications as an additional library.

I certainly will not be trying any BETA releases in the future. This has cost me two full days of lost productivity and still no resolution.
 
Upvote 0

Kevin Hartin

Active Member
Licensed User
I did that and now i get this error on compile;
Compile Error:
Uncaught translation error: com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
I saw your earlier post https://www.b4x.com/android/forum/t...iling-after-latest-sdk-update.130694/#content on a similar issue and tried your suggested fix, but it made no difference. Using the barebones test I built following your video, there is only firebasenotifications as an additional library.

I certainly will not be trying any BETA releases in the future. This has cost me two full days of lost productivity and still no resolution.
Tried on a complete virgin install on a new PC and got the same error on compile...
 
Upvote 0

Kevin Hartin

Active Member
Licensed User
Has nothing to do with the beta. There are zero known issues in that beta.

Make sure to configure the IDE to use the new SDK (Tools - Configure Path - android.jar).
Why then did you say not to run SDK Manager in 10.9 Beta? This seems to be the event that changed everything to cause the compile errors.
 
Upvote 0
Top