Android Question MultiPart SMS Sent Status

BarryW

Active Member
Licensed User
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

I used this code to send large sms and it works fine.
My question is how to capture the sent status of this code whether it success or not.
Tnx.
 

Erel

Administrator
Staff member
Licensed User
Try this:
B4X:
Sub SendLargeSms(Destination As String, Message As String)
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim smsManager As JavaObject
   smsManager = smsManager.InitializeStatic("android.telephony.SmsManager").RunMethod("getDefault", Null)
   Dim parts As Object = smsManager.RunMethod("divideMessage", Array(Message))
   Dim i As Intent
   i.Initialize("b4a.smssent", "")
   Dim pi As JavaObject
   pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
     Array(ctxt, 0, i, 134217728))
   Dim al As JavaObject
   al.InitializeNewInstance("java.util.ArrayList", Null)
   al.RunMethod("add", Array(pi))
   smsManager.RunMethod("sendMultipartTextMessage", Array(Destination, Null, parts, al, Null))
End Sub

Listen to the SmsSentStatus event with PhoneEvents.

It should be raised after the first part was sent.
 
Upvote 0

BarryW

Active Member
Licensed User
Try this:
B4X:
Sub SendLargeSms(Destination As String, Message As String)
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim smsManager As JavaObject
   smsManager = smsManager.InitializeStatic("android.telephony.SmsManager").RunMethod("getDefault", Null)
   Dim parts As Object = smsManager.RunMethod("divideMessage", Array(Message))
   Dim i As Intent
   i.Initialize("b4a.smssent", "")
   Dim pi As JavaObject
   pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
     Array(ctxt, 0, i, 134217728))
   Dim al As JavaObject
   al.InitializeNewInstance("java.util.ArrayList", Null)
   al.RunMethod("add", Array(pi))
   smsManager.RunMethod("sendMultipartTextMessage", Array(Destination, Null, parts, al, Null))
End Sub

Listen to the SmsSentStatus event with PhoneEvents.

It should be raised after the first part was sent.

But how to captude tsaka last part
 
Upvote 0

DonManfred

Expert
Licensed User
Hi sir any updates on how to capture the last message sent status?
Did you answered Erels questions? See the post before yours; you get some questions...
 
Upvote 0

BarryW

Active Member
Licensed User
Hi. I already tried Erel's code and it successfully get the first sent message event. Now how to adjust to code getting the last message event status. Tnx.
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
You need to add the PendingIntent as the last element instead of the first.

Try this:
B4X:
Sub SendLargeSms(Destination As String, Message As String)
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim smsManager As JavaObject
   smsManager = smsManager.InitializeStatic("android.telephony.SmsManager").RunMethod("getDefault", Null)
   Dim parts As JavaObject = smsManager.RunMethod("divideMessage", Array(Message))
   Dim i As Intent
   i.Initialize("b4a.smssent", "")
   Dim pi As JavaObject
   pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
     Array(ctxt, 0, i, 134217728))
   Dim size As Int = parts.RunMethod("getSize", Null)
   Dim al As JavaObject
   al.InitializeNewInstance("java.util.ArrayList", Null)
   For ii = 0 To size - 2
     al.RunMethod("add", Array(Null))
   Next
   al.RunMethod("add", Array(pi))
   smsManager.RunMethod("sendMultipartTextMessage", Array(Destination, Null, parts, al, Null))
End Sub
 
Upvote 0

BarryW

Active Member
Licensed User
Hi. i check your code and you add function getSize then a loop adding a null? What is the difference between your first code that gets the event on first msg to send and that code? Tnx
 
Upvote 0
Top