1

I was just wondering how I would get a list of messages on an Android device where I would have access to the information held by each message (particularly the time it was received, whether it was read, unread, or sent).

I found this answer, but it only seems to get the body of the messages and I would like to have more info than that.

Using new Telephony content provider to read SMS

I thought of making my own sms-like class that would contain the appropriate information I need and then somehow individually pulling that info and storing it, but I would imagine the Android api has some sort of sms class that I am somehow overlooking.

If someone could explain what is happening in the below code it might answer my question. I suspect changing the new String[] { Telephony.Sms.Inbox.Body } parameter might allow me to get the info I need, but I'm just not sure. Any help?

Cursor c = cr.query(Telephony.Sms.Inbox.CONTENT_URI, // Official CONTENT_URI from docs
                      new String[] { Telephony.Sms.Inbox.BODY }, // Select body text
                      null,
                      null,
                      Telephony.Sms.Inbox.DEFAULT_SORT_ORDER);
Community
  • 1
  • 1
MartyMiller
  • 15
  • 10

1 Answers1

2

There's rather a lot you can select, I suggest you refer to the available Telephony.Sms.Inbox, and android.provider.Telephony.TextBasedSmsColumns -

For example, change

new String[] { Telephony.Sms.Inbox.BODY },

to

new String[] { Telephony.Sms.Inbox.ADDRESS, 
    Telephony.Sms.Inbox.BODY,  Telephony.Sms.Inbox.DATE_SENT },

to also get The address of the other party and The date the message was sent.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • This seems to work for my purposes, and the separate parts are accessible via the getString method of the `Cursor c` variable shown in the above code. Thanks for your help, I just couldn't wrap my head around that one part of the code (though it seems a little obvious now...). – MartyMiller Oct 11 '14 at 21:20