如何获取Android中联系人的所有详细信息

时间:2010-02-05 05:30:40

标签: android contacts

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

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

1 个答案:

答案 0 :(得分:12)

由于它引用了弃用的类,因此必须更改Content Providers上的一些教程,这可能有所帮助。

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