Android Contacts provider get only phone contacts with all emails

后端 未结 1 651
后悔当初
后悔当初 2021-01-30 23:40

I need to get all phone contacts and their email address and photo uri:

This is what am doing:

private void getContacts() {

        ContentResolver cr =         


        
相关标签:
1条回答
  • 2021-01-30 23:55

    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?

    0 讨论(0)
提交回复
热议问题