I got a cursor retrieving all the contacts on the app that have a street address. This cursor is then passed into an Adapter. So far so good. Except I also get a bunch of low value contacts (mostly from Skype) that only have a State/Country info. Is there an easy way to modify the URI to skip those?
public Cursor getDirectoryList (CharSequence constraint) {
String[] selectionArguments = { "%"+constraint.toString()+"%" };
String selection = ContactsContract.CommonDataKinds.StructuredPostal.DISPLAY_NAME + " like ?";
Uri uri = ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI;
String sortOrder = ContactsContract.CommonDataKinds.StructuredPostal.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
Cursor cr = getContentResolver().query(uri, null, selection, selectionArguments, sortOrder);
return cr;
}
You can modify the selection and/or selectionArgs to specify more criteria, such as ensuring that the Street field is not null:
String selection =
ContactsContract.CommonDataKinds.StructuredPostal.DISPLAY_NAME + " like ? AND " +
ContactsContract.CommonDataKinds.StructuredPostal.STREET + " IS NOT NULL";
This is just SQL, so specify as many fields from ContactsContract.CommonDataKinds.StructuredPostal, and whatever conditions on them, that you want.
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