I have setup a service based on the firebase tutorial. I can send messages from my PHP page successfully. However, when I try and add functionality to the service I have hit a problem.
Its to do with the function Sub fm_MessageArrived (Message As RemoteMessage)
After the notification has been received, none of the code seems to be run.
Here is my code
I am confused because the device doesn't vibrate or show the toastmessage. Although the notification is in the notification bar and is displayed properly. I can send repeated notifications through GCM and they show on the device without issue, but the toastmessage NEVER shows.
I want to be able to start another app after the notification has been displayed but I am at a loss of how to do this, when none of the code seems to be being run in the function after the n.Notify(1) line.
Is this expected behaviour?
Is it because this code is being run from a service?
Is it because the activity is hidden (using manifest editor)
My goal eventually is to have it display a webview once the notification is clicked on but so far this is really confusing me.
Any help is appreciated.
Its to do with the function Sub fm_MessageArrived (Message As RemoteMessage)
After the notification has been received, none of the code seems to be run.
Here is my code
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private fm As FirebaseMessaging
End Sub
Sub Service_Create
fm.Initialize("fm")
UpdateFCMToken 'directly after fm.initialize
Log (fm.Token)
End Sub
Public Sub UpdateFCMToken
fm.SubscribeToTopic("general-esp-staff") 'you can subscribe to more topics
End Sub
Sub Service_Start (StartingIntent As Intent)
If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
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)
Dim Vibrate As PhoneVibrate ' For phone vibration
Vibrate.Vibrate (2000)
ToastMessageShow ("Notification Received", True)
End Sub
Sub Service_Destroy
End Sub
I am confused because the device doesn't vibrate or show the toastmessage. Although the notification is in the notification bar and is displayed properly. I can send repeated notifications through GCM and they show on the device without issue, but the toastmessage NEVER shows.
I want to be able to start another app after the notification has been displayed but I am at a loss of how to do this, when none of the code seems to be being run in the function after the n.Notify(1) line.
Is this expected behaviour?
Is it because this code is being run from a service?
Is it because the activity is hidden (using manifest editor)
B4X:
AddReplacement(<action android:name="android.intent.action.MAIN" />, )
AddReplacement(<category android:name="android.intent.category.LAUNCHER" />, )
My goal eventually is to have it display a webview once the notification is clicked on but so far this is really confusing me.
Any help is appreciated.