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:
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:
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:
The Contacts app registers to this intent filter
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/contact" />
<data android:mimeType="vnd.android.cursor.dir/person" />
<data android:mimeType="vnd.android.cursor.dir/phone_v2" />
<data android:mimeType="vnd.android.cursor.dir/phone" />
<data android:mimeType="vnd.android.cursor.dir/postal-address_v2" />
<data android:mimeType="vnd.android.cursor.dir/postal-address" />
</intent-filter>
So you can create your intent like this:
private int PICK_CONTACT = 853456;
// ...
// open contact list
void openContactPicker() {
Intent it= new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
it.setType("vnd.android.cursor.dir/postal-address");
startActivityForResult(it, PICK_CONTACT);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With