Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>[Updated] Now this can be used since API level 5</p> <pre><code>public Bitmap getAvatar(Context context, String lookupKey){ Uri uri = getDataUri(context, lookupKey); if (uri == null){ return null; } Cursor cursor = context.getContentResolver().query( uri, new String[] {ContactsContract.Data.DATA15}, null, null, null ); if (cursor == null){ return null; } try{ if (cursor.moveToFirst()){ byte [] bytes = cursor.getBlob(0); InputStream inputStream = new ByteArrayInputStream(bytes); return BitmapFactory.decodeStream(inputStream); } } finally { cursor.close(); } return null; } public Uri getDataUri(Context context, String lookupKey){ Cursor cursor = context.getContentResolver().query( Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey), new String[] {ContactsContract.Contacts.PHOTO_ID}, null, null, null ); if (cursor == null){ return null; } try { if (cursor.moveToFirst()){ long id = cursor.getLong(0); /**http://developer.android.com/reference/android/provider/ContactsContract.ContactsColumns.html#PHOTO_ID * If PHOTO_ID is null, consult PHOTO_URI or PHOTO_THUMBNAIL_URI, * which is a more generic mechanism for referencing the contact photo, * especially for contacts returned by non-local directories (see ContactsContract.Directory). */ if (id == 0){ if (Build.VERSION.SDK_INT &lt; 11){ return null; } return getPhotoThumbnailUri(context, lookupKey); } return ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, id); } } finally { cursor.close(); } return null; } //Available only for API level 11+ public Uri getPhotoThumbnailUri(Context context, String lookupKey){ Cursor cursor = context.getContentResolver().query( Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey), new String[] {ContactsContract.Contacts.PHOTO_THUMBNAIL_URI}, null, null, null ); if (cursor == null){ return null; } try{ if (cursor.moveToFirst()){ return Uri.parse(cursor.getString(0)); } } finally { cursor.close(); } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload