使用 "content://mms-sms/conversations" 获取多个联系人的对话

get conversations of multiple contacts by using "content://mms-sms/conversations"

我成功获取了列表中的所有对话,但是有一个问题,如果一个对话有多个 "recipient_ids",此代码表示无效 recipient_id 在此先感谢您的帮助

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

}

我的 MessageBoxObject class 是这个 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; }

}

recipient_ids 包含 space 个分隔的联系人 ID。

因此,为了获取联系人列表,您必须为每个 ID 标记 recipient_ids 而不是查询 content://mms-sms/canonical-address table。

cannonical-address table 有 _id 与联系人 address 相关联。

您可以通过ContactsContract.PhoneLookup查询获取联系信息。