Android Question Access more SMS Message Members from stored messages

gawie007

Member
Licensed User
Longtime User
I need more details than the 8 members of the current Sms library has.
In particular:
Status(Delivered, Read, Pending etc), Timestamp, sent time, delivered time and read time.

It seems it is possible to use reflection to access PDUS while intercepting SMS messages.


B4X:
'Parses an SMS intent and returns an array of messages
Sub ParseSmsIntent (In As Intent) As Message()
   Dim messages() As Message
   If In.HasExtra("pdus") = False Then Return messages
   Dim pdus() As Object
   Dim r As Reflector
   pdus = In.GetExtra("pdus")
   If pdus.Length > 0 Then
      Dim messages(pdus.Length) As Message
      For i = 0 To pdus.Length - 1
         r.Target = r.RunStaticMethod("android.telephony.SmsMessage", "createFromPdu", _
            Array As Object(pdus(i)), Array As String("[B"))
         messages(i).Body = r.RunMethod("getMessageBody")
         messages(i).Address = r.RunMethod("getOriginatingAddress")
      Next
   End If
   Return messages
End Sub

Can this be done with existing messages?
 

gawie007

Member
Licensed User
Longtime User
Thank you Erel.

I was hoping that I could use it to prove what time a message was sent, delivered and received.
 
Last edited:
Upvote 0

gawie007

Member
Licensed User
Longtime User
Hi Erel,
There are 3 dates:
One is a text string of the date - I think set by the receiving centre/relay station.
The second, sent date and time are only logged if the SMS is incoming (i.e. the time that someone sent the message to you)
The third one is the time that the message is delivered at the destination phone only logged if SMS is outgoing.

The last two date/time's are based on the 1/1/1970 numbers so need to be calculated. These two times are based on the time's that are set on each or the user's telephones I think - saw variances on actual messages.

Example of exported data:
3704 - Incoming, 3699 - Outgoing

_id,thread_id,address,person,date,date_sent,protocol,read,status,type,reply_path_present,subject,body,service_center,locked,error_code,seen,deletable,sim_slot,sim_imsi,hidden,group_id,group_type,delivery_date,app_id,msg_id,callback_number,reserved,pri,teleservice_id,link_url,svc_cmd,svc_cmd_content,roam_pending,spam_report,safe_message,
"3704","15","+447894561234","","Fri Jan 09 11:43:22 GMT+00:00 2015","1420803821000","0","1","-1","1","0","","Got ya message see you soon","+447802001234","0","0","1","0","0","","0","","","","0","0","","0","0","0","","0","","0","0","0"

"3699","16","+447749981234","","Thu Jan 08 19:32:13 GMT+00:00 2015","0","","1","0","2","","","First of night.","","0","0","1","0","0","","0","","","1420745543860","0","0","","0","0","0","","0","","0","0","0"

I am not sure if this is of any help????
 
Upvote 0

gawie007

Member
Licensed User
Longtime User
Hi Erel,

I found this bit of code:
B4X:
...
    this.smsBuffer.clear();
    this.sDelim = this.edDelim.getText().toString();
    Cursor localCursor1 = this.theActivity.getContentResolver().query(Uri.parse("content://sms"), null, null, null, null);
    String str1 = "";
    String[] arrayOfString1 = localCursor1.getColumnNames();
    Cursor localCursor2;
    for (int i = 0; ; i++) ...

I am not familiar with Java nor using the ContentResolver but this seems to be the part that does what I am looking for.
I hope that this is what you were talking about, especially "String[] arrayOfString1 = localCursor1.getColumnNames();", getting the names from the ContentResolved cursor.
 
Upvote 0

gawie007

Member
Licensed User
Longtime User
Fantastic Erel, Thank you! - Exactly what I was looking for.
I will include the result in case someone else ever needs more detail from STORED SMS Messages.

  • The following code:
B4X:
    Dim cr As ContentResolver
    cr.Initialize("cr")
    Dim ur As Uri
    ur.Parse("content://sms")
    Dim crsr As Cursor = cr.Query(ur, Null, "", Null, "")
    Dim Count1 As Int
  
    Count1 = crsr.ColumnCount
    Log("Number of columns = " & Count1)
    For i = 0 To Count1 - 1
         Log("Col Name " & i & " " & crsr.GetColumnName(i))
    Next

  • resulted in this Log: (Samsung Note 4 - I have not tested it on other phones yet but it may vary????)

** Activity (main) Create, isFirst = true **

Number of columns = 36

Col Name 0 _id
Col Name 1 thread_id
Col Name 2 address
Col Name 3 person
Col Name 4 date
Col Name 5 date_sent
Col Name 6 protocol
Col Name 7 read
Col Name 8 status
Col Name 9 type
Col Name 10 reply_path_present
Col Name 11 subject
Col Name 12 body
Col Name 13 service_center
Col Name 14 locked
Col Name 15 error_code
Col Name 16 seen
Col Name 17 deletable
Col Name 18 sim_slot
Col Name 19 sim_imsi
Col Name 20 hidden
Col Name 21 group_id
Col Name 22 group_type
Col Name 23 delivery_date
Col Name 24 app_id
Col Name 25 msg_id
Col Name 26 callback_number
Col Name 27 reserved
Col Name 28 pri
Col Name 29 teleservice_id
Col Name 30 link_url
Col Name 31 svc_cmd
Col Name 32 svc_cmd_content
Col Name 33 roam_pending
Col Name 34 spam_report
Col Name 35 safe_message
** Activity (main) Resume **
 
Last edited:
Upvote 0
Top