gpt4 book ai didi

Android获取所有联系人重复的名字

转载 作者:行者123 更新时间:2023-11-29 16:13:45 25 4
gpt4 key购买 nike

我正在使用这段代码:

protected String getContactInfo() {
Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null, null, null);
String str = "";
while (cursor.moveToNext()) {
str += cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + ", ";
}
cursor.close();
return str;
}

执行后该方法返回的字符串为Test1,Test1,Test1,Test1,Test1,Test1,Test1,Test1,Test1,Test1,Test1,Test1,Test1,Test1,Test2,Test2,Test2,Test2,Test2 , 鲍勃, 鲍勃, 鲍勃, 鲍勃,

当我的电话簿中只有 3 个联系人 Test1、Test2、Bob

为什么会这样?

最佳答案

试试这个...

用 URI 替换查询参数...

Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

您正在尝试从 ContactsContract.Contacts.CONTENT_URI 中获取名称,并且您正在对 ContactsContract.Data.CONTENT_URI 触发查询。

关于Android获取所有联系人重复的名字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11073814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com