如何仅从Android Studio中的特定会话中发送消息?

时间:2016-01-16 19:09:36

标签: android text sms mms

    ContentResolver cr = getContentResolver();
    String[] projection = new String[]{"body", "ct_t", "_id", "address"};
    Uri uri = Uri.parse("content://mms-sms/conversations/" + id);
    Cursor c = cr.query(uri, projection, null, null, null);

这将查询来自特定对话的所有消息,我希望仅显示已发送的消息,因为我需要区分对话的每一方。 是否像这样的uri这样的东西:

Uri uri2 = Uri.parse("content://mms-sms/conversations/" + id + "/sent/");

1 个答案:

答案 0 :(得分:1)

您需要在投影中添加几列,并在query()调用中包含选择参数。

final String[] projection = {"_id", "address", "body", "ct_t", "type", "msg_box"};
final String selection = "(type = 2 OR msg_box = 2)";
final Uri uri = Uri.parse("content://mms-sms/conversations/" + threadId);
Cursor c = getContentResolver().query(uri, projection, selection, null, null);

短信在发送时的type值为2。 MMS邮件将具有相同的值,但在msg_box列中。