B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
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.
End Sub
Sub Service_Create
'need to disable it as reading from large JdbcResultSet will cause network requests to be sent on the main thread.
'DisableStrictMode
CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
B4X:
#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
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
B4X:
'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)
SetActivityAttribute(main, android:windowSoftInputMode, adjustResize|stateHidden)
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
'End of default text.
compile -----> "There was a problem parsing the package"
It is very difficult to send text to cell phones!
Attachments
Last edited: