【问题标题】:How to get contact name details for a particular contact如何获取特定联系人的联系人姓名详细信息
【发布时间】:2012-01-11 06:48:29
【问题描述】:

我想要包含 (FAMILY_NAME, GIVEN_NAME,MIDDLE_NAME,PHONETIC_FAMILY_NAME,PHONETIC_GIVEN_NAME,PHONETIC_MIDDLE_NAME,PREFIX,SUFFIX) 的联系人姓名。

我知道上面数据的列名是以

开头的

android.provider.ContactsContract.CommonDataKinds.StructuredName

但我无法获取数据的 URI

我正在使用 api 级别 8 的设备,所以我想使用

获取这些详细信息

android.provider.ContactsContract

我已经在社区中搜索过这个,但我无法得到想要的结果。

我为此工作了 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();
        }

提前致谢。

【问题讨论】:

    标签: android contactscontract


    【解决方案1】:

    好的,试试这个,然后告诉我会发生什么,

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

    看看这个SO问题How to get the firstname and lastname from android contacts?

    编辑: 看看这个使用 android 联系人Working With Android Contacts 的完整示例,现在如果您想从任何联系人获取更多信息,请在该光标上添加特定列。更多专栏请查看ContactsContract.CommonDataKinds

    【讨论】:

    • hi user370305 如何获取特定联系人的所有联系号码,如手机号码、工作号码、家庭号码、其他号码。你有什么想法吗?????????
    • ContactsContract.CommonDataKinds.Phone其为不同类型电话号码的列名..
    • @user370305 你在这里有很好的答案。我想获取特定号码的电子邮件 ID。我可以在 android 中这样做吗?
    • @AndroidKiller - 是的,为此您必须在 ContactsContract.CommonDataKinds.Email Uri 上查询。看stackoverflow.com/questions/10117049/…
    猜你喜欢
    • 2012-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 2016-05-07
    相关资源
    最近更新 更多