English 中文(简体)
联系 pick器过滤器
原标题:Contact picker filtering
  • 时间:2012-01-13 14:15:44
  •  标签:
  • android

我以这种方式使用联系人:

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

我的问题是,能否对联系名单进行过滤? 例如,我只想看到联络名单上至少有电话号码或电子邮件地址的那些联系人。

最佳回答

我建议利用您的习惯观点进行联系,因为接触并非十分困难,而无论你是否愿意,你都可以定制。 我以这种方式履行了你所需要的职能。

见下文:

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);
}

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
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签