Android Question SMSListener Service To Listen For Login

SpinBower

Member
Licensed User
Longtime User
Hi, I have an app that needs login creds, it a security app and I want users to be able to login by texting the phone. I have a service that listens for SMS's but I dont know how to make the if statement check the message for "lostmode user pass pin" because the user, pass and pin will differ depending on the user. If someone could just give an if statement like, If Msg contains 4 words (then check if the first one is lostmode) I would handle the rest. Thanks! BTW I know that is a fake "If" statement. Heres my code:

B4X:
Sub Process_Globals
      Dim SMSIntercept1 As SmsInterceptor
End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
SMSIntercept1.Initialize2("SI",99999)
End Sub

Sub Service_Destroy
CallSub(Main, "RestartService1")
End Sub

Sub SI_MessageReceived(From As String, Msg As String) As Boolean
  If Msg = "lostmode user pass pin" Then
  Return True
  End If
End Sub
 
Last edited:

SpinBower

Member
Licensed User
Longtime User
Take the text, split it on SPACE (chr$(32)) with regex.split or something similar
In your example you get FOUR entries.

00000000111122223333
lostmode user pass pin

0 = lostmode
1 = user
2 = pass
3 = pin

Thanks! Ill tell you if it works!
 
Upvote 0

SpinBower

Member
Licensed User
Longtime User
Hi, it works but what if the user puts a captial "Lostmode"? Ive tried this:
B4X:
Sub SI_MessageReceived(From As String, Msg As String) As Boolean
ListData2 = Regex.Split(" ", Msg)
If ListData2.Get(0) = "lostmode" OR "Lostmode" Then
ToastMessageShow(ListData2.Get(0), True)
End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…