'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim PE As PhoneEvents
Dim PhId As PhoneId
Dim PhoneFlag As Int
Dim Notif1 As Notification
End Sub
Sub Service_Create
PE.InitializeWithPhoneState("PE",PhId)
Notif1.Initialize
Notif1.Icon = "icon" 'use the application icon file for the notification
Notif1.Vibrate = False
PhoneFlag = 0
End Sub
Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
main.PhoneState = State
If State = "RINGING" AND IncomingNumber<>"" Then 'incoming call
main.LastInNumber = IncomingNumber
PhoneFlag = 1
ToastMessageShow("Caller: " & IncomingNumber, True)
End If
If State = "OFFHOOK" AND IncomingNumber="" AND PhoneFlag = 1 Then 'answering to incoming call
PhoneFlag = 2
End If
If State = "OFFHOOK" AND IncomingNumber="" AND PhoneFlag = 0 Then 'out call
main.LastInNumber = IncomingNumber
PhoneFlag = 4
End If
If State = "IDLE" AND main.LastInNumber <> "" AND PhoneFlag = 2 Then 'just input call finished
PhoneFlag = 3
If main.LastInNumberContact = Null Then
StartActivity("Main")
End If
End If
If State = "IDLE" AND main.LastInNumber <> "" AND PhoneFlag = 1 Then 'just rejected input call
PhoneFlag = 0
End If
End Sub
Sub Service_Start
Notif1.SetInfo("ApplicationTitle", "Working in background...", Main)
Notif1.Sound = False
Notif1.Notify(1)
Service.StartForeground(1, Notif1)
End Sub
Sub Service_Destroy
Service.StopForeground(1)
End Sub