[英]How to get the details of a particular contact from the phone contact list?
[英]How to get contact name details for a particular contact
我想要聯系人的姓名,其中包括(FAMILY_NAME,GIVEN_NAME,MIDDLE_NAME,PHONETIC_FAMILY_NAME,PHONETIC_GIVEN_NAME,PHONETIC_MIDDLE_NAME,PREFIX,SUFFIX)。
我知道以上開頭的數據的列名
android.provider.ContactsContract.CommonDataKinds.StructuredName
但我無法獲取數據的URI 。
我正在使用api level 8的設備上工作,所以我想使用它來獲取這些細節
android.provider.ContactsContract
我在社區搜索了這個,但我無法得到理想的結果。
我在這工作了4個小時。
任何幫助將不勝感激。
我正在使用此代碼
Cursor cursor = activity.managedQuery(android.provider.ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cursor != null)
{
if (cursor.moveToFirst())
{
int rows = cursor.getCount();
int cols = cursor.getColumnCount();
do
{
int _id = cursor.getInt(cursor.getColumnIndex("_id"));
int times_contacted = cursor.getInt(cursor.getColumnIndex("times_contacted"));
int has_phone_number = cursor.getInt(cursor.getColumnIndex("has_phone_number"));
int send_to_voicemail = cursor.getInt(cursor.getColumnIndex("send_to_voicemail"));
int starred = cursor.getInt(cursor.getColumnIndex("starred"));
// Here i want the contact names But i dont know what column name i have to pass to get them
}
while (cursor.moveToNext());
}
cursor.close();
}
提前致謝。
好的,試試看,讓我知道發生了什么,
查看ContactsContract.CommonDataKinds.StructuredName類。 您可以在那里找到您要查找的所有列。
String whereName = ContactsContract.Data.MIMETYPE + " = ?";
String[] whereNameParams = new String[] { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE };
Cursor nameCur = contentResolver.query(ContactsContract.Data.CONTENT_URI, null, whereName, whereNameParams, ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME);
while (nameCur.moveToNext()) {
String given = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
String family = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
String display = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
}
nameCur.close();
看看這個問題如何從android聯系人獲取名字和姓氏?
編輯:看看這個完整的例子,用於處理Android聯系人使用Android聯系人 ,現在,如果您想從任何聯系人獲取更多信息,那么在該游標上添加特定列。 有關更多列,請查看ContactsContract.CommonDataKinds 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.