如何获取" ME" (所有者个人资料)联系人列表中的个人资料

时间:2018-05-07 14:13:06

标签: android

我的要求只是为了获得" ME"来自android的个人资料信息可能吗?如果你知道,请告诉我。

1 个答案:

答案 0 :(得分:0)

Android中的Me联系人使用API​​ 14中添加的ContactsContract.Profile处理。

您可以在下面的查询中找到如何检索基本详细信息

String[] PROJECTION = {
                            ContactsContract.CommonDataKinds.Email.ADDRESS,
                            ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
                            ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
                            ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,
                            ContactsContract.CommonDataKinds.Phone.NUMBER,
                            ContactsContract.CommonDataKinds.Phone.IS_PRIMARY,
                            ContactsContract.CommonDataKinds.Photo.PHOTO_URI,
                            ContactsContract.Contacts.Data.MIMETYPE
    };
final ContentResolver content = context.getContentResolver();
final Cursor cursor = content.query(
        // Retrieves data rows for the device user's 'profile' contact
        Uri.withAppendedPath(
                             ContactsContract.Profile.CONTENT_URI,
                             ContactsContract.Contacts.Data.CONTENT_DIRECTORY),
                             PROJECTION,

                             // Selects only email addresses or names
                             ContactsContract.Contacts.Data.MIMETYPE + "=? OR "
                             + ContactsContract.Contacts.Data.MIMETYPE + "=? OR "
                             + ContactsContract.Contacts.Data.MIMETYPE + "=? OR "
                             + ContactsContract.Contacts.Data.MIMETYPE + "=?",
                             new String[]{
                                         ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,
                                         ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE,
                                         ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
                                         ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE
                             },

                             // Show primary rows first. Note that there won't be a primary email address if the
                             // user hasn't specified one.
                             ContactsContract.Contacts.Data.IS_PRIMARY + " DESC"
);

获取光标所需的信息

String mime_type;
    while (cursor.moveToNext()) {
        mime_type = cursor.getString(7); // 7 is for index based on previous projection
        if (mime_type.equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE))
            String email = cursor.getString(/** use email index from projection*/);
        else if (mime_type.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE))
            /** Retrieve information from cursor based on your index*/
        else if (mime_type.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE))
            /** Retrieve information from cursor based on your index*/
        else if (mime_type.equals(ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE))
            /** Retrieve information from cursor based on your index*/
    }

否则您还可以使用AccountManager获取有关该用户帐户的信息