Android Contacts provider get only phone contacts with all emails Android Contacts provider get only phone contacts with all emails android android

Android Contacts provider get only phone contacts with all emails


You should be able to get all the information needed in one query on Data.CONTENT_URI,Check out "android.provider.ContactsContract.Data" table and the examples on how to query different types of data Email,Phone,Photo etc...http://developer.android.com/reference/android/provider/ContactsContract.Data.html

For example:

Cursor data = cntx.getContentResolver().query(Data.CONTENT_URI, new String[] {Data._ID,Data.MIMETYPE,Email.ADDRESS,Photo.PHOTO},Data.CONTACT_ID + "=?" + " AND " + "(" +  Data.MIMETYPE + "='" + Photo.CONTENT_ITEM_TYPE + "' OR " + Data.MIMETYPE + "='" + Email.CONTENT_ITEM_TYPE +"')",                        new String[] {String.valueOf(contactId)}, null);

Should bring you all the information you need regarding one specific contactId, you could theoretically ask for all contacts and sort the information yourself.

As for filtering gmail contacts this is a more complex issue, take a look at ACCOUNT_NAME / TYPE http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.htmlparameter and a discussion regarding this issue here:What is the default Account Type / Name for contacts on Android Contact Application?