Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim tmrServiceHook As Timer
Dim br As BroadCastReceiver
Dim pw As PhoneWakeState
Dim PE As PhoneEvents
Dim PhoneId As PhoneId
Dim nID As Int = 1
End Sub
Sub Service_Create
br.Initialize("br")
mod_functions.writelog("svc_service(), Service_Create")
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
show_notify_offline
pw.PartialLock
' // phone events
PE.InitializeWithPhoneState("PE",PhoneId)
' // set the serve hook to be called every 1 seconds
tmrServiceHook.Initialize("tmrServiceHook",1000)
End Sub
Sub Service_Start (StartingIntent As Intent)
mod_functions.writelog("svc_service(), Service_Start")
br.addAction("android.intent.action.SCREEN_OFF")
br.addAction("android.intent.action.SCREEN_ON")
br.SetPriority(2147483647)
br.registerReceiver( "")
tmrServiceHook.Enabled = True
If Not(Main.APPSET.currentChannel.IsInitialized) Then
Main.APPSET.currentChannel.Initialize
End If
' // update notification
If Main.APPSET.IsOnline Then
show_notify_online
End If
If Not(Main.APPSET.IsOnline) And Main.APPSET.currentChannel.call_state = mod_core_consts.CS_CLOSED Then
show_notify_offline
End If
If Not(Main.APPSET.IsOnline) And Main.APPSET.currentChannel.call_state = mod_core_consts.CS_SNOOZING Then
show_notify_sleeping
End If
If Not(Main.APPSET.IsOnline) And Main.APPSET.currentChannel.call_state = mod_core_consts.CS_OFFLINE Then
show_notify_offline
End If
End Sub
Sub Service_Destroy
br.unregisterReceiver
tmrServiceHook.Enabled = False
Service.StopAutomaticForeground
pw.ReleasePartialLock
mod_functions.writelog("svc_service(), Service_Destroy")
End Sub
Sub show_notify_online()
Service.AutomaticForegroundNotification = CreateNotification("Atlas PTT","Online","icon_online",Main,False,False)
End Sub
Sub show_notify_offline()
Service.AutomaticForegroundNotification = CreateNotification("Atlas PTT","Offline","icon_offline",Main,False,False)
End Sub
Sub show_notify_sleeping()
Service.AutomaticForegroundNotification = CreateNotification("Atlas PTT","Sleeping until " & DateTime.Date(Main.APPSET.snooze) & " " & DateTime.Time(Main.APPSET.snooze),"icon_offline",Main,False,False)
End Sub
Sub get_service_notification As Notification
Return Service.AutomaticForegroundNotification
End Sub
Private Sub CreateNotification(Title As String, Content As String, Icon As String, TargetActivity As Object, Sound As Boolean, Vibrate As Boolean) As Notification
mod_functions.writelog("svc_service(), CreateNotification - " & Content)
Dim p As Phone
Dim n As Notification
If p.SdkVersion >= 21 Then
Dim nb As NotificationBuilder
Dim Channel As NotificationChannelBuilder
Dim ChannelID As String = "ies_ptt"
Dim ChannelName As String = "Atlas Push To Talk"
' // Build a Channel
If Channel.ChannelsSupported Then
Channel.Initialize(ChannelID, ChannelName, Channel.IMPORTANCE_LOW)
Channel.Build
End If
nb.Initialize(ChannelID)
nb.AutoCancel = False
nb.OnGoingEvent = True
nb.DefaultSound = False ' sound
nb.DefaultVibrate = False ' vibrate
nb.DefaultLight = False
nb.ContentTitle = Title
nb.ContentText = Content
nb.setActivity(TargetActivity)
nb.SmallIcon = Icon
nb.Number = nID
' //set the return object for the notification object (n1) in this service
Return nb.GetNotification
Else
n.Initialize
n.Number = nID
n.Light = False
n.Vibrate = False
n.Sound = False
n.OnGoingEvent = True
n.Icon = Icon
n.SetInfo(Title, Content, TargetActivity)
Return n
End If
End Sub