Sub Process_Globals
Private fm As FirebaseMessaging
Private sql1 As SQL
End Sub
'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
If FirstTime Then
fm.Initialize("fm")
End If
fm.HandleIntent(StartingIntent)
End Sub
Public Sub SubscribeToTopics
'Log("subs topic")
fm.SubscribeToTopic("hadirkubroadcast") 'you can subscribe to more topics
Do While fm.Token = ""
Log("waiting")
Sleep(1000)
Loop
'Log(fm.Token)
End Sub
Sub fm_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
Log($"Message data: ${Message.GetData}"$)
If sql1.IsInitialized = False Then
sql1.Initialize(File.DirInternal,"main.db",True)
End If
If checkTableexist("pesan") Then
Dim logo As Bitmap = LoadBitmapResize(File.DirAssets, "single-icon.png", 24dip, 24dip, True)
Dim n As NB6
n.Initialize("default", Application.LabelName, "HIGH").SmallIcon(logo).AutoCancel(True)
Dim cs As CSBuilder
n.BigTextStyle(Message.GetData.Get("title"), cs.Initialize.BackgroundColor(Colors.Red).Append("").PopAll,Message.GetData.Get("body"))
n.Build(Message.GetData.Get("title"), "", "tag",pesan).Notify(1)
sql1.ExecNonQuery2("insert into pesan (judul,isi) values (?,?)",Array As Object(Message.GetData.Get("title"),Message.GetData.Get("body")))
End If
End Sub
Sub fm_TokenRefresh (Token As String)
'Log("TokenRefresh: " & Token)
End Sub
Public Sub checkTableexist(tbname As String) As Boolean
Dim rset As ResultSet = sql1.ExecQuery2("select name from sqlite_master where name=?",Array As String(tbname))
Dim hasil As Boolean
If rset.RowCount > 0 Then
hasil = True
Else
hasil = False
End If
rset.Close
Return hasil
End Sub