Android Question SMSsent and smsDelivered, follow message with Intent.getExtra

Alpay ABAY

Member
Licensed User
I am searching this for a while, I collected a few examples together. So far able to send large sms message.
I am trying to follow smssent and smsdelivered by a "message_id", which I added by intent.putExtra but
I got the final value for each message. Below message key is the referring ID of the message in DB server.

Send large sms function:
Sub SendLargeSms(Destination As String, Message As String, MessageKey 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", "")
    i.PutExtra("message_id", MessageKey)
    Dim pi As JavaObject
    pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
     Array(ctxt, 0, i, 134217728))
  
    Dim i2 As Intent
    i2.Initialize("b4a.smsdelivered", "")
    i2.PutExtra("message_id", MessageKey)
    Dim pi2 As JavaObject
    pi2 = pi2.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
     Array(ctxt, 0, i2, 134217728))
  
    Dim size As Int = parts.RunMethod("size", Null)
    Dim al, al2 As JavaObject
    al.InitializeNewInstance("java.util.ArrayList", Null)
    al2.InitializeNewInstance("java.util.ArrayList", Null)
    For ii = 0 To size - 2
        al.RunMethod("add", Array(Null))
        al2.RunMethod("add", Array(Null))
    Next
    al.RunMethod("add", Array(pi))
    al2.RunMethod("add", Array(pi2))
    smsManager.RunMethod("sendMultipartTextMessage", Array(Destination, Null, parts, al, al2))
End Sub

Intent.GetExtra("message_id") should return uniqie message id, but returns only the last one when there back to back multiple messages.
I think I tried check everything about this, but sure I am missing a parameter something. Need help?

Intersect smssentevent:
Sub PE_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
    Dim MsgId As String = Intent.GetExtra("message_id")
    Do_SmsSentNotifyServer(MsgId)
    Log ("SMSSentStatus:" & Success & ":" & ErrorMessage & ":" & MsgId)
    Log(Intent.GetData)
End Sub
 
Last edited:
Solution
So At last I found it on android documentation.

B4X:
    pi2 = pi2.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
     Array(ctxt, 0, i2, 134217728))

On creating intent, 134217728 was FLAG for updating current, I replace it with FLAG_ONE_SHOT = 1073741824, now it works charming.
More information is here, Android FLAG_ONE_SHOT

Thank you

Alpay ABAY

Member
Licensed User
So At last I found it on android documentation.

B4X:
    pi2 = pi2.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
     Array(ctxt, 0, i2, 134217728))

On creating intent, 134217728 was FLAG for updating current, I replace it with FLAG_ONE_SHOT = 1073741824, now it works charming.
More information is here, Android FLAG_ONE_SHOT

Thank you
 
Upvote 0
Solution

Alpay ABAY

Member
Licensed User
So At last I found it on android documentation.

B4X:
    pi2 = pi2.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
     Array(ctxt, 0, i2, 134217728))

On creating intent, 134217728 was FLAG for updating current, I replace it with FLAG_ONE_SHOT = 1073741824, now it works charming.
More information is here, Android FLAG_ONE_SHOT

Thank you

Another correction to that, this was ok but it is making a problem about intent from SDK31.
Error was "(version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE".
To fix that issue the final code is below.

B4X:
pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", Array(ctxt, Rnd(0, 0x7fffffff), i,  67108864   ))
 
Upvote 0
Top