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

标签 android sms

我成功获取列表中的所有对话,但有一个问题,如果一个对话有多个“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 类是这样的 公共(public)类 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 包含空格分隔的联系人 ID。

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

cannonical-address 表具有与联系人 地址 关联的 _id

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

关于android - 使用 "content://mms-sms/conversations"获取多个联系人的对话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29824955/

相关文章:

ios - 在 iOS 中处理事件

android - 运行非离线语言时的 SpeechRecognizer ERROR_SERVER

Android - DeleteIntent,如何使用?

android - 选项卡出现在操作栏上方

android - 除非应用程序正在运行,否则应用程序不会响应收到的短信。

java - 安卓短信上下文菜单

android - 使用 ActionBarSherlock 实现滑动抽屉导航

java - 为什么 SocketChannel 调用 read(byteBuffer) 会抛出 java.net.SocketException : recvfrom failed: ECONNRESET (Connection reset by peer)

javascript - 使用 Node.JS SerialPort 发送短信

java - android AppWidget : SMS query works on emulator, 但不在真实设备上