【问题标题】:get conversations of multiple contacts by using "content://mms-sms/conversations"使用“content://mms-sms/conversations”获取多个联系人的对话
【发布时间】:2015-04-23 13:29:03
【问题描述】:

我成功获取了列表中的所有对话,但有一个问题,如果一个对话有多个“recipient_ids”,此代码显示无效的接收者 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 类是这个 公共类 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; }

}

【问题讨论】:

  • 看来MessageBoxObject 是您的自定义类,因此在这种情况下,您应该修复您的代码,使其适用于多个收件人 ID。
  • 它有 getter 和 setter,比如 String recipient_number;字符串消息计数;字符串接收者ids;字符串 sn-p; String readcount, sn-p_cs, type, error, has_attachment, status;长日期;整数读取;公共字符串 getRecipient_ids() { 返回接收者 ID; } 公共无效 setRecipient_ids(字符串收件人 ID){ this.recipient_ids = 收件人 ID; }

标签: android sms


【解决方案1】:

recipient_ids 包含空格分隔的联系人 ID。

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

cannonical-address 表有_id 与联系人address 关联。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 2015-05-18
    • 1970-01-01
    • 2012-03-27
    相关资源
    最近更新 更多