views:

100

answers:

0

I am trying to do a Contacts search on Android using ContactsContract.

I would like to search on multiple parameters, e.g. - Where name = myname AND email = myemail AND nickname = mynickname, etc.

I have it working w/ just name, but need the syntax to add email and nickname as search params. I know they are stored separately from display name & have a different format. The code below is what is working for the search by just name.

How can I add to the selection variable to also search by email and nickname?

CODE:

    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + ("1") + "'";
    selection += "AND " + ContactsContract.Contacts.DISPLAY_NAME + "= '" + cp.name + "'";
    Uri uri = ContactsContract.Contacts.CONTENT_URI;        
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
    Cursor myCursor = mApp.managedQuery(uri, null, selection, null, sortOrder);