7

给定一个联系人 ID,我可以通过对每个字段进行不同的查询来获取各种联系人详细信息(如姓名、电话、电子邮件 ID 等)。

但是有没有一种方法可以通过一次查询来获取与此联系人 ID 相关的所有详细信息?

4

1 回答 1

12

由于它引用了不推荐使用的类,因此必须更改一些关于内容提供程序的教程,这可能会有所帮助。

import android.provider.ContactsContract.Contacts;
import android.database.Cursor;

// Form an array specifying which columns to return, you can add more.
String[] projection = new String[] {
                         ContactsContract.Contacts.DISPLAY_NAME,
                         ContactsContract.CommonDataKinds.Phone
                         ContactsContract.CommonDataKinds.Email
                      };

Uri contacts =  ContactsContract.Contacts.CONTENT_LOOKUP_URI;
// id of the Contact to return.
long id = 3;

// Make the query. 
Cursor managedCursor = managedQuery(contacts,
                     projection, // Which columns to return 
                     null,       // Which rows to return (all rows)
                                 // Selection arguments (with a given ID)
                     ContactsContract.Contacts._ID = "id", 
                                 // Put the results in ascending order by name
                     ContactsContract.Contacts.DISPLAY_NAME + " ASC");
于 2010-02-05T05:51:34.377 回答