从联系人列表中选择姓名

时间:2012-04-04 05:37:00

标签: android

如何从联系人列表中获取名字和姓氏?

2 个答案:

答案 0 :(得分:1)

请查看Contact Manager示例项目以获取执行此操作的代码。

答案 1 :(得分:0)

试试这个:

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[] str = given.split(' ');
       String fname=str[0];  // FIRST NAME
       String lname=str[str.length-1]; // LAST NAME
}
nameCur.close();

有关详细信息,请参阅此帖子How to get the firstname and lastname from android contacts?