3

How can Telephony.Sms.Conversations be used to retrieve convo information to String?

I tried:

ContentResolver cr = context.getContentResolver();
Cursor convo = cr.query(Telephony.Sms.Conversations.CONTENT_URI,
                        new String[] { Telephony.Sms.Conversations.ADDRESS,
                                       Telephony.Sms.Conversations.PERSON },
                        null,
                        null,
                        Telephony.Sms.Conversations.DEFAULT_SORT_ORDER);

How ever I get error invalid column address. when I remove address I get invalid column person. What column's does this class provide? (I couldn't find anything on the API reference page or any examples online. btw I already have a working code to retrieve inbox and outbox but I would like to get conversations too (I mean title and num of msges), without matching inbox and outbox results)

Arijoon
  • 2,184
  • 3
  • 24
  • 32
  • ran into the same problem, found the answer here http://stackoverflow.com/questions/4702206/illegalargumentexception-invalid-column – Daniel H Dec 03 '14 at 00:35
  • Did you ever solve this? I'm having the exact same issue – Matt Apr 25 '16 at 20:03

1 Answers1

3

You can only get "msg_count" and "snippet" values from Telephony.Sms.Conversations, and you can get the "address" value from Telephony.TextBasedSmsColumns.

private static final String[] SMS_CONVERSATIONS_PROJECTION = new String[]{"msg_count", "snippet"};
Cursor cursor = cr.query(Telephony.Sms.Conversations.CONTENT_URI,
            SMS_CONVERSATIONS_PROJECTION, null, null,Telephony.Sms.Conversations.DEFAULT_SORT_ORDER);
while(cursor.moveToNext()) {
    int msg_count = cursor.getInt(cursor.getColumnIndex("msg_count"));
    String snippet = cursor.getString(cursor.getColumnIndex("snippet"));
}
cursor.close;

It's inconvenient for us without "address", "date" and so on.
Telephony.Sms.Conversation

lovefish
  • 657
  • 6
  • 18