Android - Getting a list of contacts with street addresses, but not as inexpensive as Skype, where the address is only a city and state

I have a cursor that retrieves all the contacts in the application that have a street address. Then this cursor is passed to the adapter. So far, so good. In addition, I also get a bunch of inexpensive contacts (mostly from Skype) that only have state / country information. Is there an easy way to change the URIs to skip them?

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; } 
+7
android android-contentresolver simplecursoradapter street-address
source share
1 answer

You can modify selection and / or selectionArgs to specify more criteria, for example, so that the Street field is not null:

 String selection = ContactsContract.CommonDataKinds.StructuredPostal.DISPLAY_NAME + " like ? AND " + ContactsContract.CommonDataKinds.StructuredPostal.STREET + " IS NOT NULL"; 

It's just SQL, so specify as many fields from ContactsContract.CommonDataKinds.StructuredPostal and any conditions for them that you want.

+4
source share

All Articles