Android getting contacts photo from data.Email query

前端 未结 4 1192
半阙折子戏
半阙折子戏 2021-01-14 05:22

I am making a autocomplete Field that queries contacts by Display name and Email. When someone clicks on the desired contact after the filtering that contact is added to a l

4条回答
  •  没有蜡笔的小新
    2021-01-14 06:04

    When you want to access the photo of a contact, you need to specify the contact photo URI, for example using this method:

    public Uri getContactPhotoUri(long contactId) {
        Uri photoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
        photoUri = Uri.withAppendedPath(photoUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
        return photoUri;
    }
    

    But for contactId you must use:

    String id = ContactsContract.CommonDataKinds.Photo.CONTACT_ID;
    long contactId = Long.parseLong(id);
    

    Please note that a common error is to use ContactsContract.Contacts._ID instead ContactsContract.CommonDataKinds.Photo.CONTACT_ID

    I hope that can help you.

提交回复
热议问题