如何从 Android 联系人中获取名字和姓氏? [英] How to get the first name and last name from Android contacts?

查看:28
本文介绍了如何从 Android 联系人中获取名字和姓氏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Android 联系人中获取以下字段?我用的是安卓 2.2.

How to get the following fields from Android contacts? I used Android 2.2.

  1. 名称前缀
  2. 名字
  3. 中间名
  4. 姓氏
  5. 名称前缀
  6. 拼音名字
  7. 拼音中间名
  8. 拼音姓氏

推荐答案

查看 ContactsContract.CommonDataKinds.StructuredName 类.您可以在那里找到您要查找的所有列.试试这样:

Look at ContactsContract.CommonDataKinds.StructuredName class. You can find there all columns you are looking for. Try sth like this:

    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();

它返回联系人中的所有姓名.更准确地说,您可以将联系人 ID 作为附加参数添加到查询中 - 您将获得特定联系人的地址.

It returns all names in contacts. To be more precise you can add a contact id as an additional parameter to the query - you will get address for particular contact.

这篇关于如何从 Android 联系人中获取名字和姓氏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆