Please help my messages only comes when i have open the app if the app is not open then they do not come please help
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="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:usesCleartextTraffic, "true")
SetApplicationAttribute(android:allowBackup, "false")
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetActivityAttribute(SendsmschatV2, android:windowSoftInputMode, adjustPan|stateHidden)
CreateResourceFromFile(Macro, Themes.DarkTheme)
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, Core.NetworkClearText)
AddPermission(com.majeur.launcher.permission.UPDATE_BADGE)
AddPermission(com.sec.android.provider.badge.permission.READ)
AddPermission(com.sec.android.provider.badge.permission.WRITE)
AddPermission(com.htc.launcher.permission.READ_SETTINGS)
AddPermission(com.htc.launcher.permission.UPDATE_SHORTCUT)
AddPermission(com.anddoes.launcher.permission.UPDATE_COUNT)
AddPermission(com.majeur.launcher.permission.UPDATE_BADGE)
AddPermission(com.huawei.launcher3.permission.READ_SETTINGS)
AddPermission(com.huawei.launcher3.permission.WRITE_SETTINGS)
AddPermission(com.huawei.launcher2.permission.READ_SETTINGS)
AddPermission(com.huawei.launcher2.permission.READ_SETTINGS)
AddPermission(com.huawei.android.launcher.permission.WRITE_SETTINGS)
AddPermission(com.huawei.android.launcher.permission.READ_SETTINGS)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(com.sonyericsson.home.permission.BROADCAST_BADGE)
AddPermission(com.anddoes.launcher.permission.UPDATE_COUNT)
AddApplicationText(
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="$PACKAGE$.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
)
CreateResource(xml, provider_paths,
<files-path name="name" path="shared" />
)
CreateResource(values, colors.xml,
<resources>
<color name="actionbar">#0098FF</color>
<color name="statusbar">#ff006db3</color>
<color name="textColorPrimary">#ffffffff</color>
<color name="navigationBar">#ff006db3</color>
</resources>
)
CreateResource(values-v20, theme.xml,
<resources>
<style name="LightTheme" parent="@android:style/Theme.Material.Light">
<item name="android:colorPrimary">@color/actionbar</item>
<item name="android:colorPrimaryDark">@color/statusbar</item>
<item name="android:textColorPrimary">@color/textColorPrimary</item>
<item name="android:navigationBarColor">@color/navigationBar</item>
</style>
</resources>
)
'End of default text.
'End of default text.
'
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Private fm As FirebaseMessaging
Dim cursor1 As Cursor
End Sub
Sub Service_Create
fm.Initialize("fm")
End Sub
Public Sub SubscribeToTopics
'fm.SubscribeToTopic("general") 'you can subscribe to more topics
'fm.SubscribeToTopic("No0781703474") 'you can subscribe to more topics
cursor1 = Starter.SQL1.ExecQuery("SELECT phone AS Phone,Sex FROM Register")
If cursor1.RowCount > 0 Then
' For i = 0 To cursor1.RowCount - 1
cursor1.Position =0
Dim Phoneg As String
Phoneg = cursor1.Getstring("Phone")
Log(Phoneg)
fm.SubscribeToTopic(Phoneg) 'you can subscribe to more topics
'Next
End If
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}"$)
Starter.strTitle = Message.GetData.Get("title")
Starter.strBody = Message.GetData.Get("body")
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"),SendsmschatV2)
'n.Build("Important Good Work sula!!!", "Content", "tag", Me).Notify(9)
n.Notify(1)
'CallSub2(Sendsms, "SetText", Message.GetData.Get("title"))
'If Message.GetData.ContainsKey("title") Then
'Dim sms As String = Message.GetData.Get("title")
'Log(sms)
'End If
End Sub
Sub Service_Destroy
End Sub
B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Public SQL1 As SQL
Dim SQL1 As SQL
'Dim cursor1 As Cursor
Public Provider As FileProvider
Dim cursor As Cursor
Private nid As Int = 1
Private serializator As B4XSerializator
Dim SQLDataBasePath = File.DirInternal As String
Dim SQLDateBaseName = "studentdbmk.sql" As String
'Dim SQLTabelName = "persons" As String
Public CurrentIndex As Int 'index of the current entry
Public RowNumber As Int 'number of rows
Public rp As RuntimePermissions
Public IDList As List 'list containing the IDs of the database
'we need it because the IDs can be different from the list indexes
'if we delete an entry its ID is lost
Dim cursor As Cursor
'Variables for Edit
'the Edit Activity has two modes "Add" and "Edit"
Public EditMode As String
Type StudentDatacompare (admno As String, Names As String,First As String, Second As String, Subject As String, Firsagg As String,Secagg As String, Differencemks As String, Differenceagg As String, categorymks As String,categoryagg As String)
'Variables for Filter
'variable for the filter query,
'defined in the btnFilter_Click routine
'and will be used In the DBWebView ShowTable routine
Public FilterQuery As String
'flag for the filter active or inactive
Public flagFilterActive As Boolean
'Boolean operator used in the filter
'can be OR or AND
Public FilterBooleanOperator As String
'Variables used to hold the selected indexes of the Spinners
Public SelectedFirstName = 0 As Int
Public SelectedLastName = 0 As Int
Public SelectedCity = 0 As Int
Dim strTitle As String
Dim strBody As String
End Sub
Private Sub CreateMessage(Body As String) As Byte()
Dim m As Message
m.Initialize
m.Body = Body
m.From = "currentName"
Return serializator.ConvertObjectToBytes(m)
End Sub
Public Sub SendMessage(Body As String)
CreateMessage(Body)
'client.Publish2("all", CreateMessage(Body), 0, False)
End Sub
Sub Service_Create
'initialize the variables
Provider.Initialize
CurrentIndex = -1
RowNumber = 0
EditMode = "Add"
FilterQuery = ""
flagFilterActive = False
FilterBooleanOperator = "OR "
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
'File.Delete(File.DirInternal, "studentdbm.sql") ' only for testing, removes the database
'check if the database already exists
Dim jo As JavaObject
jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("UK")))
If File.Exists(SQLDataBasePath, SQLDateBaseName) = False Then
'copy the default DB
File.Copy(File.DirAssets, SQLDateBaseName, SQLDataBasePath, SQLDateBaseName)
'if not, initialize it
SQL1.Initialize(SQLDataBasePath, SQLDateBaseName, True)
'and create it
'CreateDataBase
SQLInit
CallSubDelayed(Firebasemessaging, "SubscribeToTopics")
Else
SQL1.Initialize(SQLDataBasePath, SQLDateBaseName, True)
'SQLInit
CallSubDelayed(Firebasemessaging, "SubscribeToTopics")
' Dim SQLQry As String = "DELETE FROM Allacounts"
'SQL1.ExecNonQuery("DELETE FROM Register")
'SQL1.ExecNonQuery("DROP TABLE IF EXISTS AcademicsLoadCurve")
'SQL1.ExecNonQuery("DROP TABLE IF EXISTS AcademicsLoadCurveP1P2")
'SQL1.ExecNonQuery("DROP TABLE IF EXISTS AcademicsLoadCompare")
'Private query As String
' query = "CREATE TABLE AcademicsLoadCurve ( Names TEXT, Class TEXT, Stream TEXT, Subject TEXT, Total NUMERIC, Grade TEXT, Mid NUMERIC,Ends NUMERIC,Term TEXT, Years TEXT, id INTEGER,Phone TEXT )"
'SQL1.ExecNonQuery(query)
'
'query = "CREATE TABLE AcademicsLoadCurveP1P2 ( Names TEXT, Class TEXT, Stream TEXT, Subject TEXT, Total NUMERIC, Grade TEXT, Mid NUMERIC,Ends NUMERIC,Term TEXT, Years TEXT, id INTEGER,Phone TEXT )"
'query = "CREATE TABLE AcademicsLoadCompare ( Names TEXT, Class TEXT, Stream TEXT, Subject TEXT, Total NUMERIC, Grade TEXT, Mid NUMERIC,Ends NUMERIC,Term TEXT, Years TEXT, id INTEGER,Phone TEXT )"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE Anouncements (anounce TEXT,Account TEXT,ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE)"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE SMSlist (Account Text, Names Text,Phone text,Sex text,ID INTEGER,Phone2 text )"
'SQL1.ExecNonQuery(query)
'SQL1.ExecNonQuery("DROP TABLE IF EXISTS Register")
'query = "CREATE TABLE Register (Code Text, Phone Text, Email Text, Sex Text, ID INTEGER)"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE Academics ( Names TEXT, Class TEXT, Stream TEXT, Subject TEXT, Total NUMERIC, Grade TEXT, Mid NUMERIC,Ends NUMERIC,Term TEXT, Years TEXT, id INTEGER,Phone TEXT )"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE Balances (Account Text,Names text, Class text,Stream text,Amount NUMERIC, ID INTEGER,Phone Text )"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE Alevelreport (Account Text, Points Text,Name text,Subject text, ID INTEGER )"
'SQL1.ExecNonQuery(query)
'SQL1.ExecNonQuery("DROP TABLE IF EXISTS Terms ")
'SQL1.ExecNonQuery("DROP TABLE IF EXISTS SMSlist")
'SQL1.ExecNonQuery("DROP TABLE IF EXISTS Recievedsms")
'SQL1.ExecNonQuery("DROP TABLE IF EXISTS Studentphoto2")
'query = "CREATE TABLE Academicspast ( Names TEXT, Class TEXT, Stream TEXT, Subject TEXT, Total NUMERIC, Grade TEXT, Mid NUMERIC,Ends NUMERIC,Term TEXT, Years TEXT, id INTEGER )"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE Statement (Account Text,Names text,DESCRIPT text,DEBITAMNT text,CREDITAMNT text, TREF text,TRDATE nvarchar(50),BAL text)"
'SQL1.ExecNonQuery(query)
'SQL1.ExecNonQuery("DROP TABLE IF EXISTS Register")
'query = "CREATE TABLE Register (Code Text, Phone Text, Email Text, Sex Text, ID INTEGER)"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE Recievedsms (Daterecieved Text, Sms text,ID INTEGER)"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE SMSlist (Account Text, Names Text,Phone text,Sex, ID INTEGER )"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE Eventsinfo (Events TEXT, Class TEXT,Stream TEXT, Dates TEXT,Tcode TEXT, Id INTEGER Not Null PRIMARY KEY AUTOINCREMENT UNIQUE,Term TEXT,Years TEXT)"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE Years (Years Text,ID INTEGER )"
'SQL1.ExecNonQuery(query)
'query = "CREATE TABLE Studentphoto2 (name TEXT, image BLOB,Account TEXT)"
'SQL1.ExecNonQuery(query)
' query = "CREATE TABLE Terms (Term Text,Account Text,ID INTEGER )"
' SQL1.ExecNonQuery(query)
End If
End Sub
Sub SQLInit