Can anyone help me?
I have been playing with the firebase notification example from Erel.
It works perfectly, that is, I always get a notification.
However, the content of the notification is not available if the app was in background.
For example if my message body says 'Hello' and my app is currently in the foreground. Then I get a notification and when I click on it, the content 'Hello' is placed in the label1.
But, if my app is not in the foreground, then I still get the notification, but when I touch it, the activity starts but not knowing what the content is.
Here is the service...
This is the main Activity.
So, if my app is visible, and I send 'Hello', the notification appears and when I touch it, label1 is filled out with the message. (the content also appears in the notification)
But if my app is not visible, the notification appears, but no content when I touch it. (the content does not appear in the notification, just the app title)
Thank you for anybody pointing out where I've gone wrong.
I have been playing with the firebase notification example from Erel.
It works perfectly, that is, I always get a notification.
However, the content of the notification is not available if the app was in background.
For example if my message body says 'Hello' and my app is currently in the foreground. Then I get a notification and when I click on it, the content 'Hello' is placed in the label1.
But, if my app is not in the foreground, then I still get the notification, but when I touch it, the activity starts but not knowing what the content is.
Here is the service...
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
Private fm As FirebaseMessaging
Public notificationCount As Int=0
End Sub
Sub Service_Create
fm.Initialize("fm")
End Sub
Public Sub SubscribeToTopics
'just commented out to test we can send to a token
'fm.SubscribeToTopic("general") 'you can subscribe to more topics
End Sub
Public Sub SubscribeToTopic(topic As String)
fm.SubscribeToTopic(topic) 'you can subscribe to more topics
End Sub
public Sub token
CallSubDelayed2(Main,"showtoken",fm.Token)
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"
Dim contentToSend As String=Message.GetData.Get("body")
n.SetInfo2( "M=" & Message.GetData.Get("title"), Message.GetData.Get("body"), contentToSend , Main)
n.Light=True
n.Sound=True
n.Notify(1 )
End Sub
Sub Service_Destroy
End Sub
This is the main Activity.
So, if my app is visible, and I send 'Hello', the notification appears and when I touch it, label1 is filled out with the message. (the content also appears in the notification)
But if my app is not visible, the notification appears, but no content when I touch it. (the content does not appear in the notification, just the app title)
B4X:
#Region Project Attributes
#ApplicationLabel: Test Firebase
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: 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 Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Label1 As Label
Private lblToken As Label
Private btnGetToken As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("layout1")
End Sub
public Sub showtoken(token As String)
lblToken.Text=token
End Sub
Sub Activity_Resume
Dim contents As String
Dim in As Intent
in = Activity.GetStartingIntent
If in.HasExtra("Notification_Tag") Then
contents=in.GetExtra("Notification_Tag")
ToastMessageShow(contents,True) 'Will log the tag
Label1.Text=contents
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnGetToken_Click
CallSubDelayed(FirebaseMessaging,"token")
End Sub
Thank you for anybody pointing out where I've gone wrong.