It is easy to open the Android Contact App to show all contacts and pick one of them:
in Activity:
private int PICK_CONTACT = 853456;
// ...
// open contact list
void openContactPicker() {
Intent it= new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(it, PICK_CONTACT);
}
// when back from intent: use pick result
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// ...
switch (requestCode) {
case PICK_CONTACT:
if (dataOk(data)) {
extractContactInfo(data);
} else {
showErrorMessage();
}
break;
// ...
}
But is it possible to set some filter criteria, so that the Contact App will only display those contacts which have specified elements - e.g. a complete postal info, or a proper email, or a telephone number?
My App needs the postal info, the currently implemented work-flow is like that:
- User clicks button to open contacts
- Contact App is started, displays all contacts
- user selects one
- back in my activity the contact is checked
- postal info available -> do the right thing
- postal info not available -> message box
Since many contacts do not have a postal info, in most cases a message box 'sorry no postal info available for this contact' will be shown. This is not an acceptable behavior.
One alternative is - I'm just implementing this - to query the contacts database inside the app and do the filtering in my own code, but using this approach has some implications:
- the app requires the read contacts permission, which might be a no go for many users
- a contact picker has to be implemented, which possibly looks different than the one the user is familiar with
So, setting some criteria for the Contacts App seems a much more elegant way of doing this.
The App should run on Android 2.3.3 and higher.
Questions:
- Is it possible on 2.3.3 to set filter criteria (especially sth. like 'has_postal_information') for the Contacts App, when starting it via startActivityForResult?
- If not: is it possible on later OS versions?