Sub SI_MessageReceived (From As String, Body As String) As Boolean
'test messages
ToastMessageShow("Text from " & From, True)
Log ("From before cut" & From)
'strips out the first numbers of the incoming phone number
From = From.SubString2(From.Length-7, From.Length)
'ToastMessageShow("Chopped from " & From, True)
Dim listOfContacts As List
Dim Contacts2 As Contacts2
listOfContacts = Contacts2.GetAll(True,False)
For i = 0 To listOfContacts.Size - 1
Dim Contact As Contact
Contact = listOfContacts.Get(i)
'this strips out the first numbers of the phone list
Dim phonenumber As String
Dim startphone, endphone As Int
If Contact.phonenumber <>"" AND Contact.phonenumber.Length > 8 Then
phonenumber = Contact.phonenumber
startphone = phonenumber.Length-7
endphone = phonenumber.Length
phonenumber = phonenumber.SubString2(startphone,endphone)
Log ("From after the cut" & From)
If From = phonenumber Then
'bunch of test messages
ToastMessageShow("PH " & phonenumber & " From " & From, True)
Log("PH " & phonenumber & " From after cut " & From)
ToastMessageShow("Incoming text from " & Contact.Name, True)
TTS1.Speak("Text from " & Contact.Name, True)
'write the body text to a file where it gets picked up to read by the notify in another activity (works)
File.WriteString(File.DirInternal, "body.txt","From " & Contact.Name & " " & Body)
'stop the rest of the loop running?
Return
Else
ToastMessageShow("No matching contact", True)
Log("PH " & phonenumber & " From after cut " & From)
Return
End If
End If
Next
End Sub