android - context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null,null, null);

标签 android

您好,我正在 Android 联系人搜索模块中工作。我正在查询下方运行。

cur = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null , null ,null, null);

从这个查询中我得到了多次结果。我做错了什么吗?我想要 DISTINCT 结果集。

请帮助我。

最佳答案

我想你的意思是你有一些联系人的重复记录。所以你必须为你的查询添加条件

String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
                + ("1") + "'";
        String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
                + " COLLATE LOCALIZED ASC";
cur = context.getContentResolver().query(
                ContactsContract.Contacts.CONTENT_URI, projection, selection
                        + " AND " + ContactsContract.Contacts.HAS_PHONE_NUMBER
                        + "=1", null, sortOrder);// this query only return contacts which had phone number and not duplicated

关于android - context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null,null, null);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13172268/

相关文章:

android - "fastboot boot <kernel>"在内部是如何工作的?

android - 在 netbeans 上启动第一个 android hello world 的问题

java - 在 Android 中获取和显示日期信息

android - 向布局添加文本?

android - 带有嵌套导航图的循环引用

c# - Xamarin 缺少引用

eclipse - 将 android 应用程序版本 2.3 更改为 4.2 android

android - 如何停止当前正在播放的铃声?

Android 布局作为具有可选功能的按钮

android - Retrofit2 多部分上传图像和其他数据