Code for the above question...
I have the following in the activity code
...........................................................................
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
StartService(smsmodule)
End Sub
Below is the code from my service -- smsmodule --.
(Please excuse the many LOG and TOAST entries)
............................................................
Type=Service
Version=2.71
@EndOfDesignText@
#Region Service Attributes
#StartAtBoot: false
#End Region
'Service module
Sub Process_Globals
Type Message (Address As String, Body As String)
End Sub
Sub Service_Create
Dim SI As SmsInterceptor
SI.Initialize2("SI", 999)
ToastMessageShow("went into service create",True)
Log("#0")
ToastMessageShow("#0",True)
End Sub
Sub Service_Start(startingIntent As Intent)
Log("#1")
ToastMessageShow("#1",True)
If startingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
Log("#2")
ToastMessageShow("#2",True)
Dim messages() As Message
messages = ParseSmsIntent(startingIntent)
For i = 0 To messages.Length - 1
Log(messages(i))
Next
ToastMessageShow("went into startingIntent.Action",True)
End If
End Sub
'Parses an SMS intent and returns an array of messages
Sub ParseSmsIntent (In As Intent) As Message()
Log("#3")
ToastMessageShow("#3",True)
ToastMessageShow("went into parseSMSIntent.Action",True)
Dim messages() As Message
If In.HasExtra("pdus") = False Then Return messages
Dim pdus() As Object
Dim r As Reflector
pdus = In.GetExtra("pdus")
If pdus.Length > 0 Then
Log("#4")
ToastMessageShow("#4",True)
Dim messages(pdus.Length) As Message
Dim From As String
Dim smsin As String
For i = 0 To pdus.Length - 1
r.Target = r.RunStaticMethod("android.telephony.SmsMessage", "createFromPdu", _
Array As Object(pdus(i)), Array As String("[B"))
messages(i).Body = r.RunMethod("getMessageBody")
messages(i).Address = r.RunMethod("getOriginatingAddress")
ToastMessageShow(r.RunMethod("getMessageBody"),True)
smsin = r.RunMethod("getMessageBody")
From = r.RunMethod("getOriginatingAddress")
If smsin.ToLowerCase = "secret" Then
SI_MessageReceived(From,smsin)
End If
Next
End If
Return messages
End Sub
Sub SI_MessageReceived (From As String, Body As String) As Boolean
Dim smsOut As PhoneSms
Log("#6")
ToastMessageShow("#6",True)
If Body.ToLowerCase = "secret" Then
Log("#7")
ToastMessageShow("#7",True)
ToastMessageShow(Body, True)
smsOut.Send(From,"from SI_MessageReceived")
ToastMessageShow("Auto-reply sent", True)
Return True
Else
Log("#8")
ToastMessageShow("#8",True)
Return False
End If
End Sub
Sub Button2_Click
ExitApplication
End Sub