您正在尋找ContactsContract.RawContacts.DisplayPhoto
,
下面是來自docs(它是寫作照片到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.
}
}
以下是如何閱讀:
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.
}
}
你有沒有試過[此鏈接](http://stackoverflow.com/a/3509210/3800164),似乎很有用你的問題? –