Reputation: 131
I successfully get the all conversations in list, but there is a problem, if a conversation have more than one "recipient_ids", this code says invalid recipient_id thanks in advance for help
public static void getAllMessagesInList(Context context) {
Uri uri = Uri.parse("content://mms-sms/conversations?simple=true");
String[] reqCols = new String[] { "_id", "recipient_ids", "message_count", "snippet", "date", "read" };
Cursor cursor = context.getApplicationContext().getContentResolver().query(uri, reqCols, null, null, "date DESC");
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
MessageBoxObject messageBoxObject = new MessageBoxObject();
messageBoxObject.setRecipient_ids(cursor.getString(cursor.getColumnIndex(reqCols[1])));
messageBoxObject.setMessage_count(cursor.getString(cursor.getColumnIndex(reqCols[2])));
messageBoxObject.setSnippet(cursor.getString(cursor.getColumnIndex(reqCols[3])));
messageBoxObject.setDate(cursor.getLong(cursor.getColumnIndex(reqCols[4])));
messageBoxObject.setRead(cursor.getInt(cursor.getColumnIndex(reqCols[5])));
ConstantsValues.messageBoxObjects.add(messageBoxObject);
}
}
cursor.close();
}
my MessageBoxObject class is this public class MessageBoxObject {
String recipient_number;
String message_count;
String recipient_ids;
String snippet;
String readcount, snippet_cs, type, error, has_attachment, status;
Long date;
int read;
public int getRead() { return read; }
public void setRead(int read) { this.read = read; }
public Long getDate() { return date; }
public void setDate(Long date) { this.date = date; }
public String getRecipient_ids() { return recipient_ids; }
public void setRecipient_ids(String recipient_ids) { this.recipient_ids = recipient_ids; }
public String getMessage_count() { return message_count; }
public void setMessage_count(String message_count) { this.message_count = message_count; }
public String getRecipient_number() { return recipient_number; }
public void setRecipient_number(String recipient_number) { this.recipient_number = recipient_number; }
public String getSnippet() { return snippet; }
public void setSnippet(String snippet) { this.snippet = snippet; }
}
Upvotes: 2
Views: 1412
Reputation: 2158
recipient_ids
contains space separated contact ids.
So in order to get list of contacts you must tokenize recipient_ids
than query content://mms-sms/canonical-address
table for each id.
cannonical-address
table has _id
associated with contact address
.
Than you can query by ContactsContract.PhoneLookup
to get contact info.
Upvotes: 4