如何获取联系人姓名信息的特定联系人 [英] 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,$p$pFIX,SUFFIX).
I want the Name of the Contact which includes (FAMILY_NAME, GIVEN_NAME,MIDDLE_NAME,PHONETIC_FAMILY_NAME,PHONETIC_GIVEN_NAME,PHONETIC_MIDDLE_NAME,PREFIX,SUFFIX).
我知道,以
android.provider.ContactsContract.CommonDataKinds.StructuredName
但我无法得到的 URI 数据。
But i am unable to get the URI of the data.
我和API级别工作8设备上,所以我想用获取这些细节
I was working on device with api level 8 so i want to fetch these details using
android.provider.ContactsContract
我有搜索有关此commumnity但我无法得到期望的结果。
I have searched about this in commumnity but i can't get the desired result.
我工作4小时这一点。
任何帮助将AP preciated。
Any help will be appreciated.
我就是用这个code
I was using this code
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();
}
在此先感谢。
Thanks in advance.
推荐答案
好吧,试试这个,让我知道发生什么事,
Ok, Try this, and let me know what happen,
看<一href="http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.StructuredName.html"相对=nofollow> ContactsContract.CommonDataKinds.StructuredName 类。你可以找到有你正在寻找所有列。
Look at ContactsContract.CommonDataKinds.StructuredName class. You can find there all columns you are looking for.
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();
看这太问题<一href="http://stackoverflow.com/questions/4301064/how-to-get-the-firstname-and-lastname-from-android-contacts">How获得从Android的联系人名字和姓氏?
编辑:看看这个完整的例子与机器人接触的使用Android的联系人的,现在,如果你想从任何联系人的详细信息,然后在该光标添加特定列。对于更多的列一下 ContactsContract.CommonDataKinds 。
Look at this complete example for working with android contacts Working With Android Contacts, Now if you want to get more info from any contacts then add a particular column on that cursor. For more columns look at ContactsContract.CommonDataKinds.
这篇关于如何获取联系人姓名信息的特定联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!