You're looking for ContactsContract.RawContacts.DisplayPhoto
,
Here's the official usage example from the docs (it's for writing a photo into a RawContact):
public void writeDisplayPhoto(long rawContactId, byte[] photo) {
Uri rawContactPhotoUri = Uri.withAppendedPath(
ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
try {
AssetFileDescriptor fd =
getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "rw");
OutputStream os = fd.createOutputStream();
os.write(photo);
os.close();
fd.close();
} catch (IOException e) {
// Handle error cases.
}
}
Here's how to read it:
public byte[] readDisplayPhoto(long rawContactId) {
byte[] photo;
Uri rawContactPhotoUri = Uri.withAppendedPath(
ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
try {
AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "r");
FileInputStream is = fd.createInputStream();
is.read(photo);
is.close();
fd.close();
return photo
} catch (IOException e) {
// Handle error cases.
}
}