'Service module
Sub Process_Globals
Type Message (Address As String, Body As String)
Dim servicerunning As Boolean
Dim notification1 As Notification
'Dim theinterceptor As SmsInterceptor
End Sub
Sub Service_Create
If notification1.IsInitialized = False Then
notification1.Initialize
notification1.Icon = "notification_bw_x50"
notification1.Vibrate = False
notification1.Sound = False
notification1.SetInfo("TEST-SMS", "Waiting For Messages", "")
notification1.Notify(1)
End If
'theinterceptor.Initialize2("smsint", 999)
Log("MessageInterceptor Service initialized")
End Sub
Sub Service_Start(startingIntent As Intent)
Service.StartForeground(1, notification1)
servicerunning=True
Log("MessageInterceptor Service Started")
If startingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
'Dim messages() As Message
Dim messages As List
messages = ParseSmsIntent(startingIntent)
For i = 0 To messages.Size - 1
Log(messages.get(i))
Next
notification1.Icon = "notification_color_x50"
notification1.Vibrate = True
notification1.Sound = True
notification1.SetInfo("New Messages", "Message received.", "")
notification1.Notify(1)
End If
End Sub
'Parses an SMS intent and returns an array of messages
Sub ParseSmsIntent (In As Intent) As List
Dim messages_list As List
messages_list.Initialize
If In.HasExtra("pdus") = False Then Return messages_list
Dim pdus() As Object
Dim r As Reflector
pdus = In.GetExtra("pdus")
Dim messagesMap As Map
messagesMap.Initialize
If pdus.Length > 0 Then
For i = 0 To pdus.Length - 1
Dim msg As Message
r.Target = r.RunStaticMethod("android.telephony.SmsMessage", "createFromPdu", _
Array As Object(pdus(i)), Array As String("[B"))
msg.Body = r.RunMethod("getMessageBody")
msg.Address = r.RunMethod("getOriginatingAddress")
If messagesMap.ContainsKey(msg.Address) Then
Dim existing As Message
existing = messagesMap.Get(msg.Address)
existing.Body = existing.Body & msg.Body
Else
messagesMap.Put(msg.Address, msg)
messages_list.Add(msg)
End If
Next
End If
Return messages_list
End Sub
Sub Service_Destroy
Log("MessageInterceptor Service Destroyed")
' theinterceptor.StopListening()
Service.StopForeground(1)
servicerunning=False
End Sub
Sub smsInt_MessageReceived (From As String, Body As String) As Boolean
notification1.Icon = "notification_color_x50"
notification1.Vibrate = True
notification1.Sound = True
notification1.SetInfo("New Messages", "Message received.", "")
notification1.Notify(1)
Log("the interceptor does nothing now")
Return True
End Sub