Android Question how to use httputils2 in smsinterceptor?

fricentric

Member
Licensed User
Longtime User
I am using the example code from http://www.b4x.com/android/forum/threads/smsinterceptor-working-example.31890 for the smsinterceptor.
I have removed the httputils2service and tried the call but i still dont get the response back.

B4X:
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")
         
            Dim job4 As HttpJob

    'Send a POST request
  job4.Initialize("Job4", Me)
  job4.PostString("http://www.mysite.com/api", "smsin="&smsin&"&From="&From)
            If smsin.ToLowerCase = "hello" Then
                SI_MessageReceived(From,smsin)
            End If
        Next
    End If
     
    Return messages
End Sub  

Sub JobDone (Job As HttpJob)
  Log("JobName = " & Job.JobName & ", Success = " & Job.Success)

End Sub

What might be the issue? i am using httputils2 2.01 version.
 

fricentric

Member
Licensed User
Longtime User
To answer my own question i had not added the permission for receive sms in my manifest editor.
B4X:
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(smsmodule,
<intent-filter>
    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
 
Upvote 0
Top