Android Question SMS with country code - not sent

PhilipK

Member
Licensed User
Longtime User
I'm sending SMS texts with plain mobile phone numbers, without a problem, using:

B4X:
        Dim r As Reflector
        r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
        r.RunMethod4("sendTextMessage", Array As Object(PhoneNumber, Null, Text, Null, Null), _
            Array As String("java.lang.String", "java.lang.String", "java.lang.String", _
                "android.app.PendingIntent", "android.app.PendingIntent"))

However some numbers have the country code eg +3478...... and the SMS send fails.

How do you send SMS texts to mobile phones abroad?

Thanks.
 

PhilipK

Member
Licensed User
Longtime User
Hi, Klaus

I have tried with an 00 but no luck.

My code:

B4X:
        'Get rid of leading Plus
        If PhoneNumber.Contains("+") Then PhoneNumber=PhoneNumber.Replace("+","00")
       
        Dim r As Reflector
        r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
        r.RunMethod4("sendTextMessage", Array As Object(PhoneNumber, Null, Text, Null, Null), _
            Array As String("java.lang.String", "java.lang.String", "java.lang.String", _
                "android.app.PendingIntent", "android.app.PendingIntent"))

Ideas welcome! Thanks.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi,
Did you try directly from the regular Android phone app? (not from your app)
If you didn't then try to send (International) sms directly.. (not local).
 
Upvote 0

PhilipK

Member
Licensed User
Longtime User
Hi Beja, the Android phone's SMS app accepts and sends a 0034... text. I have sent a text to myself with 0044 prefix and received it.
 
Upvote 0

PhilipK

Member
Licensed User
Longtime User
Hi, Do I assume that the SMSmanager can't handle country codes? Although that is odd if the android app can...
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Still I (think) it is from your carrier company.. send sms directly, not to yourself, but to someone outside your country.
just for troubleshooting.
 
Upvote 0

PhilipK

Member
Licensed User
Longtime User
I just don't know why it's an issue. However, it's been resolved using the following:

B4X:
        Dim Sms As PhoneSms
        Sms.Send(PhoneNumber,MessageText)

Thanks
 
Upvote 0
Top