final boolean IS_HONEYCOMB = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; String phoneNumber = "+1 416 385 7805"; ContentResolver contentResolver = context.getContentResolver(); Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.LOOKUP_KEY, IS_HONEYCOMB ? ContactsContract.Contacts.PHOTO_THUMBNAIL_URI : ContactsContract.Contacts._ID, }; Cursor cursor = contentResolver.query( uri, projection, null, null, null); if (cursor != null && cursor.moveToNext()) { long contactId = cursor.getLong(0); String lookupKey = cursor.getString(1); String thumbnailUri = cursor.getString(2); cursor.close(); }
So, if sdk is honeycomb or higher, you have a thumbnail uri of the contact. Or you can build uri to search like this:
Uri uri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
PS If you already know the id contact and / or search key , you can build Uri from the line:
search: content://com.android.contacts/contacts/lookup/{lookup key}/{contact id} thumbnail: content://com.android.contacts/contacts/{contact id}/photo
Therefore, it is better to cache these values.
Mussa May 14 '16 at 10:30 2016-05-14 10:30
source share