Android Contacts provider get only phone contacts with all emails

南笙酒味 提交于 2019-12-02 16:43:32
Raanan

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.html parameter and a discussion regarding this issue here: What is the default Account Type / Name for contacts on Android Contact Application?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!