SMS Tutorial?

rfresh

Well-Known Member
Licensed User
Longtime User
Do we have an SMS tutorial?

I look here but did not see one.

And I didn't see anything in the Beginners Guide2.0.pdf doc.

I want to send an SMS text message to my phone and be able to intercept the message text.

Thanks...
 

rfresh

Well-Known Member
Licensed User
Longtime User
Thanks Erel.

I have a Service module already. So I have to put my Send SMS code in a Service module vs an Activity module?
 
Last edited:
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Hmmm...I'm trying to use the code below, but I never get the SMS test message on my phone. I have SMS enabled and send and receive SMS messages everyday on my phone, so I know it works.

I have tried this code in my Service module and in an Activity, but I never get the SMS message on my phone.

Am I missing some more needed code?

B4X:
AddPermission("android.permission.SEND_SMS") (in Manifest)

Dim Sms1 As PhoneSms
Sms1.Send(3105551212,"Android SMS test")
Log("SMS Sent")

(I use my own cell phone number in place of 3105551212)
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
I re-read the docs and it seems .Send wants the phone number as a string so I changed my code from this

B4X:
Sms1.Send(3105551212,"Android SMS test")

to this

B4X:
Sms1.Send("3105551212","Android SMS test")

but I still didn't receive the SMS test message.
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
I finally got the SMS messages to be received on my phone from my app. I guess my carrier had a delivery delay, but they are coming in ok now.

However, my app's SMS events are not firing.

B4X:
'I get the message on my phone but this event does not write to the log:
Sub MessageReceived (From As String, Body As String) As Boolean
   Log("+++++++++++++++++SMS From:" & From)
   Log("+++++++++++++++++SMS Body:" & Body)
End Sub

'I can send out an SMS message ok and now receive it but these two events do not write to the log:
Sub SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
   Log("+++++++++++++++++SmsSentStatus PhoneNumber:" & PhoneNumber)
   Log("+++++++++++++++++SmsSentStatus SmsSentStatus:" & Success)
   Log("+++++++++++++++++SmsSentStatus ErrorMessage:" & ErrorMessage)
   Log("+++++++++++++++++SmsSentStatus Intent:" & Intent)
End Sub

Sub SmsDelivered (PhoneNumber As String, Intent As Intent)
   Log("+++++++++++++++++SmsDelivered PhoneNumber:" & PhoneNumber)
End Sub

My setup code is this:

B4X:
Dim Sms2Intercept As SmsInterceptor
Sms2Intercept.Initialize2 ("MessageReceived", 999)
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Resolved:

I discovered that my SMS receiver code needed to look like this. I didn't pick up anywhere that I had to add my dimmed interceptor onto the beginning of the events:

B4X:
Sub SI2_MessageReceived (From As String, Body As String) As Boolean

vs what I originally had:

B4X:
Sub MessageReceived (From As String, Body As String) As Boolean

I dimmed SI2 as

B4X:
Dim SI2 As SmsInterceptor
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Thanks...unfortunately, I'm not the sharpest developer around so I completely missed that point about adding the SI2_ to the front of the event name.

I agree and hope too this will help someone else.
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Sending a message is very simple: Basic4android - Phone

Intercepting messages is done with SmsInterceptor: Basic4android - Phone

You need to add a service to your project with this object.

On my Acer 10 inch Tablet with WiFi only, I installed one of the SMS apps from the Android Market. When I send an SMS message to that app (I'm using HeyWire with a supplied free phone number) the app shows it but the SMS Interceptor does not 'see it' come in.

Does the SMS Interceptor only work on phones with a native cellular connection and not devices with only wifi?
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
That's probably right Erel. Heywire is handling it themselves so the msg interceptor doesn't see it. Thanks...
 
Upvote 0

Hilton

Active Member
Licensed User
Longtime User
sending sms

I am new to basic4android and would just like to thank you for documenting what you tried to get it all going - I found it very helpful.

Hilton.
 
Upvote 0

abner69

Member
Licensed User
Longtime User
Using Heywire...

(I'm using HeyWire with a supplied free phone number) the app shows it but the SMS Interceptor does not 'see it' come in.

@rfresh, I am interested in using the HeyWire service to send sms too! do you have any information on how to send the formatted sms msg to the heywire app?
 
Last edited:
Upvote 0

kechiksp

New Member
Hmmm...I'm trying to use the code below, but I never get the SMS test message on my phone. I have SMS enabled and send and receive SMS messages everyday on my phone, so I know it works.

I have tried this code in my Service module and in an Activity, but I never get the SMS message on my phone.

Am I missing some more needed code?

B4X:
AddPermission("android.permission.SEND_SMS") (in Manifest)

Dim Sms1 As PhoneSms
Sms1.Send(3105551212,"Android SMS test")
Log("SMS Sent")

(I use my own cell phone number in place of 3105551212)

hi.i'm still new to this softwazre.and i'm developing an app that require the sms service.where should i put the "android.permission.SEND_SMS"?
 
Upvote 0

BaGRoS

Active Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

Dim si, sr As SmsInterceptor
Dim SMSs As PhoneSms

End Sub

...

Sub Service_Create

      'PE.Initialize("PE")
      'si outgoing messages
      si.Initialize2("si",998)
      si.ListenToOutgoingMessages
      
      'incoming messages
      sr.Initialize2("sr",999)      
      
End Sub

...

Sub sr_MessageReceived (From As String, Body As String) As Boolean
    
   Log(From)
   
    If From.Contains("880166533") Then
    Log ("Odebrało się")
        'Code of delete the message
    End If
    
End Sub

...

Sub si_MessageSent (MessageId As Int)
    Dim sm As SmsMessages
    Dim res As List = sm.GetByMessageId(MessageId)
    If res.Size > 0 Then
        Dim msg As Sms
        msg = res.Get(0)
        Log(msg)
....

outgoing messages work fine
but incoming not work... :sign0163:
 
Last edited:
Upvote 0
Top