【问题标题】:Getting only "normal" contacts仅获取“正常”联系人
【发布时间】:2014-06-18 13:55:04
【问题描述】:

目前在我的应用程序中,我使用以下光标查询获取所有联系人。

String[] columnsToReturn = new String[] {
    ContactsContract.Contacts._ID,
    ContactsContract.Contacts.DISPLAY_NAME_PRIMARY
};

Cursor contactsCursor = getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, columnsToReturn, null, null, null);

这会返回所有联系人,包括 Skype、WhatsApp 等。我不想要这些。我只想要“正常”的。那些不适合任何应用程序的应用程序,只是存储在您的 Google 帐户中的应用程序。我该怎么做?

另外,我可以排除用户自己的条目吗?例如,我的名字多次出现在我所有不同的电子邮件地址的列表中。

【问题讨论】:

    标签: android android-contacts android-cursor


    【解决方案1】:

    ContactsContract.Contacts 表包含“合并”联系人。

    ...代表相同的原始联系人聚合的记录 人。

    如果要查询特定账户或账户类型的联系人,需要使用RawContacts。例如,对于 Google 联系人,这将是:

    Cursor c = getContentResolver().query(
            RawContacts.CONTENT_URI,
            new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY },
            RawContacts.ACCOUNT_TYPE + "= ?",
            new String[] { "com.google" },
            null);
    
    ArrayList<String> myContacts = new ArrayList<String>();
    int contactNameColumn = c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY);
    while (c.moveToNext())
    {
        // You can also read RawContacts.CONTACT_ID to read the
        // ContactsContract.Contacts table or any of the other related ones.
        myContacts.add(c.getString(contactNameColumn));
    }
    

    【讨论】:

      猜你喜欢
      • 2013-12-16
      • 2017-09-07
      • 1970-01-01
      • 2011-10-30
      • 2013-08-19
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多