如何获得联系人姓名信息的特定联系人
问题描述:
我想要的联系人,其中包括(FAMILY_NAME,GIVEN_NAME,MIDDLE_NAME,PHONETIC_FAMILY_NAME,PHONETIC_GIVEN_NAME,PHONETIC_MIDDLE_NAME,前缀,后缀)的名称。如何获得联系人姓名信息的特定联系人
我知道,与
android.provider.ContactsContract.CommonDataKinds.StructuredName
开始上述数据的列名,但我无法得到数据的URI。
我工作的设备符合API级别8,所以我想用
android.provider.ContactsContract
我在commumnity搜索这个获取这些详细信息,但我不能让预期的结果。
我在这工作了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();
看看这太问题How to get the firstname and lastname from android contacts?
编辑:看这个完整的例子与Android通讯录Working With Android Contacts工作,现在,如果你想从任何联系人的详细信息,然后添加一个特定列那个光标。更多专栏请看ContactsContract.CommonDataKinds。
工作谢谢你的回答 –
非常感谢..................................... .......... –
欢迎好友... :-) – user370305