Android Question How to change SMS sent state as Received or Failed etc...

wy328

Member
Licensed User
Longtime User
I use the following code to write message to log, when the message was sent.
But the SMS writen by these code can not show sent state.
My question is that how can I change the SMS sent state to Received or Failed?
So that user can see if the message was sent correctly or not.
Thanks!

B4X:
Sub AddMessageToLogs(body As String, address As String)
  Dim r As Reflector
  r.Target = r.CreateObject("android.content.ContentValues")
  r.RunMethod3("put", "address", "java.lang.String", address, "java.lang.String")
  r.RunMethod3("put", "body", "java.lang.String", body, "java.lang.String")
  Dim contentValues As Object = r.Target
  r.Target = r.GetContext
  r.Target = r.RunMethod("getContentResolver")
  r.RunMethod4("insert", Array As Object( _
      r.RunStaticMethod("android.net.Uri", "parse", Array As Object("content://sms/sent"), _
        Array As String("java.lang.String")), _
      contentValues), Array As String("android.net.Uri", "android.content.ContentValues"))
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Use this instead i suggest

--------------------------------------------------------------------------------------------------------------
Send2 (PhoneNumber AsString, Text AsString, ReceiveSentNotification AsBoolean, ReceiveDeliveredNotification AsBoolean)
Sends an Sms message. Note that this method actually sends the message (unlike most other methods that
create an intent object).
You can use PhoneEvents to handle the SmsSentStatus and SmsDelivered events.
ReceiveSentNotification - If true then the SmsSentStatus event (PhoneEvents) will be raised when the message is sent.
ReceiveDeliveredNotification - If true then the SmsDelivered event (PhoneEvents) will be raised when the message is delivered.
Note that the two above notifications might incur an additional payment.
--------------------------------------------------------------------------------------------------------------
 
Upvote 0
Top