如何仅从 Android Studio 中的特定对话中获取已发送的消息?

How to get only sent messages from specific conversation in Android Studio?

    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/");

您需要向 projection 添加几列,并在 query() 中包含 selection 参数] 打电话。

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 列中。