MartyMiller
MartyMiller

Reputation: 15

How to get a list of messages on Android device - keep access to extra info

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);

Upvotes: 1

Views: 1391

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201447

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.

Upvotes: 2

Related Questions