如何获取Android中的联系人的所有细节 [英] How to obtain all details of a contact in Android
本文介绍了如何获取Android中的联系人的所有细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于接触ID,我能获得各种联系信息(如姓名,电话,电子邮件ID等),通过不同的查询为每个字段。
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相关的细节?
But is there a method to obtain all the details associated with this contact id by making a single query?
推荐答案
不得不更改的 内容提供商 因为它引用德precated类,这可能帮助。
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");
这篇关于如何获取Android中的联系人的所有细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文