Android Question sms send2 - MAXIMUM 160 CHARS?

vangogh

Active Member
Licensed User
Longtime User
hello!

I am sending sms

SMS SEND:
Private Sub btnSend_Click
   ' this send the sms (it works)
    Dim ps As PhoneSms
    ps.Send2(myRecipient.Text, myText.Text, True, True)
End Sub

Sub PEsms_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
    ' this get the status event
    ToastMessageShow("SMS sentstatus: esito=" & Success & " -err=" & ErrorMessage, False)
End Sub

It works if the sms lenght is <= 160 chars

If the sms is LONGER than 160 character, I get a Success = False, ErrorMessage = "GENERIC_FAILURE"


of course, if I send and sms using the android sms app, I can write longer messages - as I know it will be split (by the carrier?) and "rebuild" when received

the question is:

HOW can I send longer messages?
(more than 160 chars)

Thank you!
 
Last edited:
Solution
try this:


B4X:
Sub SendLargeSms(Destination As String, Message As String)

    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
    Dim parts As Object
    parts = r.RunMethod2("divideMessage", Message, "java.lang.String")
    r.RunMethod4("sendMultipartTextMessage", _
        Array As Object(Destination, Null, parts, Null, Null), _
        Array As String("java.lang.String", "java.lang.String", _
        "java.util.ArrayList", "java.util.ArrayList", "java.util.ArrayList"))

End Sub

sirjo66

Well-Known Member
Licensed User
Longtime User
try this:


B4X:
Sub SendLargeSms(Destination As String, Message As String)

    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
    Dim parts As Object
    parts = r.RunMethod2("divideMessage", Message, "java.lang.String")
    r.RunMethod4("sendMultipartTextMessage", _
        Array As Object(Destination, Null, parts, Null, Null), _
        Array As String("java.lang.String", "java.lang.String", _
        "java.util.ArrayList", "java.util.ArrayList", "java.util.ArrayList"))

End Sub
 
Upvote 0
Solution

vangogh

Active Member
Licensed User
Longtime User
try this:


B4X:
Sub SendLargeSms(Destination As String, Message As String)

    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
    Dim parts As Object
    parts = r.RunMethod2("divideMessage", Message, "java.lang.String")
    r.RunMethod4("sendMultipartTextMessage", _
        Array As Object(Destination, Null, parts, Null, Null), _
        Array As String("java.lang.String", "java.lang.String", _
        "java.util.ArrayList", "java.util.ArrayList", "java.util.ArrayList"))

End Sub

it works, thank you

BUT sadly this methoid seems not to manage (raise) the "sent status" and the "delivered" events...

so I cannot know if the message was sent or not....

waiting for a solution, I trim the messages to 160chars (bad bad thing)
maybe I could manually split the sms but I cannot be sure about the order the recipient will receive them..."
 
Last edited:
Upvote 0
Top