Givenacontactid,Icanobtainvariouscontactdetails(likename,phone,email-id,etc)bymaking Given a contact id, I can obtain various contact details (like name, phone, email-id, etc) by making different queries for a each of these fields. 给定联系
Given a contact id, I can obtain various contact details (like name, phone, email-id, etc) by making different queries for a each of these fields.
给定联系人ID,我可以通过对每个字段进行不同的查询来获取各种联系人详细信息(如姓名,电话,电子邮件ID等)。
But is there a method to obtain all the details associated with this contact id by making a single query?
但是,是否有方法通过进行单个查询来获取与此联系人ID相关的所有详细信息?
1 个解决方案
#1
12
Had to change a bit of the tutorial on Content Providers since it referenced deprecated classes, this might help.
不得不改变内容提供者的一些教程,因为它引用了弃用的类,这可能会有所帮助。
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");