如何获取特定联系人的联系人姓名详细信息
我想要联系人姓名,其中包括(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,试试这个,让我知道会发生什么,
看看 ContactsContract.CommonDataKinds.StructuredName 类。您可以在那里找到您要查找的所有列。
看看这个问题如何获取名字和姓氏来自 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.
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.