3

我正在使用以下查询检索上次短信/彩信对话的列表:

String[] columns={"type", "address", "date", "body", "conversation_id"};
Cursor cursor=context.getContentResolver().query(Uri.parse("content://mms-sms/conversations"), columns,  null, null, "date desc");

谁能告诉我如何获得相同的查询以及联系人姓名?具体领域ContactsContract.PhoneLookup.DISPLAY_NAME

我的意思是,我了解如何在单独的查询中获取这些字段,但我需要在与对话相同的查询中获取它。

4

2 回答 2

0

尝试这个:

Log.i(TAG,"load_contact for "+Phone_numb);
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(Phone_numb));
String name = "?";

ContentResolver contentResolver = getContentResolver();
Cursor contactLookup = contentResolver.query(uri, 
    new String[] { BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);

try {
    if (contactLookup != null && contactLookup.getCount() > 0) {
        contactLookup.moveToNext();
        name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
    } else {
         return Phone_numb;
    }
} finally {
    if (contactLookup != null) {
        contactLookup.close();
    }
}
于 2014-02-04T09:14:08.623 回答
0

我使用这个解决方法做了这个:

val uri = Uri.parse("content://sms")
val projection = arrayOf("DISTINCT $THREAD_ID", _ID, ADDRESS, BODY, DATE, TYPE)
val selection = "$THREAD_ID IS NOT NULL) GROUP BY ($THREAD_ID"

contentResolver.query(uri, projection , selection, null, "date DESC")

如果有人知道更好的方法,请分享。

于 2018-12-01T21:21:16.117 回答