如何获取特定联系人的联系人姓名详细信息

发布于 2024-12-19 07:11:27 字数 1616 浏览 0 评论 0原文

我想要联系人姓名,其中包括(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();
        }

提前致谢。

I want the Name of the Contact which includes (FAMILY_NAME, GIVEN_NAME,MIDDLE_NAME,PHONETIC_FAMILY_NAME,PHONETIC_GIVEN_NAME,PHONETIC_MIDDLE_NAME,PREFIX,SUFFIX).

I know that column names of the above data that starts with

android.provider.ContactsContract.CommonDataKinds.StructuredName

But i am unable to get the URI of the data.

I was working on device with api level 8 so i want to fetch these details using

android.provider.ContactsContract

I have searched about this in commumnity but i can't get the desired result.

I am working for 4 hours on this.

Any help will be appreciated.

I was using this code

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

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装爱人 2024-12-26 07:11:27

好的,试试这个,让我知道会发生什么,

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

看看这个问题如何获取名字和姓氏来自 Android 联系人?

编辑: 查看这个使用 Android 联系人的完整示例 使用 Android 联系人,现在如果您想获取更多信息来自任何联系人,然后在该光标上添加特定列。有关更多列,请参阅 ContactsContract.CommonDataKinds

Ok, Try this, and let me know what happen,

Look at ContactsContract.CommonDataKinds.StructuredName class. You can find there all columns you are looking for.

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

Look at this SO question How to get the firstname and lastname from android contacts?

EDIT: Look at this complete example for working with android contacts Working With Android Contacts, Now if you want to get more info from any contacts then add a particular column on that cursor. For more columns look at ContactsContract.CommonDataKinds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文