联系方式选择器过滤 [英] Contact picker filtering

查看:161
本文介绍了联系方式选择器过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的是联系人选择器是这样的:

I use the contact picker in this way:

    Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
    this.startActivityForResult(intent, PICK_CONTACT_REQUEST);

我的问题是,如果可以过滤莫名其妙的联系人列表?例如,我只想看到在联系人列表中的联系人的那些具有至少一个电话号码或电子邮件地址。

My question is if somehow the contact list can be filtered? For example I want to see only those contacts in the contact list which have at least a phone number or an email address.

推荐答案

我会建议使用您的自定义视图的contacts-它不是相当困难,你可以定制你想要的东西。我个人实现这样的功能需要。

I would suggest to use your custom view for the contacts- it is not rather difficult and you can customize it however you want. I personally implemented that way the functionality you need.

在这里看到:

String PHONE_CONTACTS_ORDER_CLAUSE = ContactsContract.Contacts.DISPLAY_NAME
        + " ASC";

List<PhoneContact> contacts = new ArrayList<PhoneContact>(); // I have defined the bean PhoneContact
String[] projection = { ContactsContract.Contacts._ID,
        ContactsContract.Contacts.DISPLAY_NAME }; //Choose the columns you need
Cursor cursor = this.getContentResolver().query(
        ContactsContract.Contacts.CONTENT_URI, projection, null/* the place for your where clause*/, null/* the place for your where args*/,
        PHONE_CONTACTS_ORDER_CLAUSE);
startManagingCursor(cursor);

int contactIdIdx = cursor.getColumnIndex(ContactsContract.Contacts._ID);
int displayNameIdx = cursor
        .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
while (cursor.moveToNext()) {
    PhoneContact contact = new PhoneContact(); // This is a class i defined, use the data the way you like.
    contact.setContactId(cursor.getString(contactIdIdx));
    contact.setDisplayName(cursor.getString(displayNameIdx));
    contacts.add(contact);
}

修改
写评论时,对不起得到分心的接触式ID实际上是联系相关数据的不同内容提供商之间的粘合剂。这些都是一些更多的供应商可以用它来查看是否有任何关联的电话或电子邮件与该联系人:

EDIT Sorry got distracted when writing the comment: the Contact id is actually the glue between the different content providers of the Contact related data. These are a few more providers you can use to see whether there are any associated phones or emails with the contact:

ContactsContract.CommonDataKinds.Phone.CONTENT_URI
ContactsContract.CommonDataKinds.Email.CONTENT_URI

这篇关于联系方式选择器过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆