【问题标题】:How can I retrieve only Android contacts that have an entry in the People app?如何仅检索在“人脉”应用中有条目的 Android 联系人?
【发布时间】:2013-08-07 19:12:25
【问题描述】:

我想在 Android 应用程序中包含一个自动完成文本框,适配器是用户联系人的显示名称列表,所以我从这个开始:

    private static final String[] CONTACT_COLUMNS = new String[] { ContactsContract.Contacts.DISPLAY_NAME, BaseColumns._ID };

    List<String> contacts = new ArrayList<String>();
    ContentResolver cr = this.getContentResolver();
    Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, CONTACT_COLUMNS, null, null, null);
    while (cursor.moveToNext()) {
        String name = cursor.getString(0);
        contacts.add(name);
    }
    cursor.close();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.contact_list_item, contacts.toArray(new String[] {}));
    MultiAutoCompleteTextView txtFriends = (MultiAutoCompleteTextView) findViewById(R.id.newVisitFriends);
    txtFriends.setAdapter(adapter);
    txtFriends.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

但是,该查询的结果会返回来自每个来源的每个联系人,包括许多重复的姓名和可能在某个时候向用户的 gmail 帐户发送过电子邮件的各种电子邮件地址。

有什么方法可以只检索出现在“人脉”应用中的联系人?

【问题讨论】:

    标签: android android-contentprovider android-contacts


    【解决方案1】:

    您可能应该将 cr.query 过滤到具有电话号码 (ContactsColumns.HAS_PHONE_NUMBER) 的联系人:

    http://developer.android.com/reference/android/provider/ContactsContract.ContactsColumns.html#HAS_PHONE_NUMBER

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多