【问题标题】:Retrieve all phone contacts regardless their group检索所有电话联系人,无论他们的组
【发布时间】:2015-04-17 21:58:43
【问题描述】:

我在检索所有电话联系人时遇到问题。

当使用以下选择子句时,我没有收到未与组关联保存的联系人(例如 google 特定帐户组):

    final static String SELECTION = (Utils.hasHoneycomb()
            ? Contacts.DISPLAY_NAME_PRIMARY
            : Contacts.DISPLAY_NAME) + "<>''" + " AND " + Contacts.IN_VISIBLE_GROUP + "=1";

...
... 

// onCreateLoader() code:
return new CursorLoader(getActivity(), Contacts.CONTENT_URI, ContactsQuery.PROJECTION,
            ContactsQuery.SELECTION, null, ContactsQuery.SORT_ORDER);

从 Google 教程或演示项目之一获得此 sn-p。

按照文档,我意识到Contacts.IN_VISIBLE_GROUP + "=1" 导致过滤不属于任何组的联系人,所以我简单地删除了这个条件,期望也获得不属于任何组的联系人:

final static String SELECTION = (Utils.hasHoneycomb()
            ? Contacts.DISPLAY_NAME_PRIMARY
            : Contacts.DISPLAY_NAME) + "<>''";

使用此 SELECTION 子句后 - 我得到了所有联系人,包括不属于任何组的联系人,但现在 我得到了属于某个组的所有联系人的重复

请帮助我了解如何执行不重复返回所有联系人的查询

提前致谢

【问题讨论】:

    标签: android android-sqlite android-contacts google-contacts-api


    【解决方案1】:
    Uri contactUri = data.getData();
                    String[] projection = {ContactsContract.CommonDataKinds.Phone.NUMBER,
                            ContactsContract.Contacts.DISPLAY_NAME};
                    Cursor cursor = activity.getContentResolver()
                            .query(contactUri, projection, null, null, null);
                    cursor.moveToFirst();
    int column = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
                    String number = cursor.getString(column);
    
                    int column1 = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
                    String name = cursor.getString(column1);
    

    【讨论】:

    • 我不明白。您提供的 sn-ps 演示了如何接收特定的联系方式,而不是所有的联系方式。
    • 这个 sn-ps 可以得到我所有的联系人姓名和号码。抱歉没有得到你想要的结果
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多