我想从联系人中获取照片,如果某些联系人没有照片来返回默认照片(只有剪影),我该怎么做? 提前致谢, 狼。
最佳答案
您可以使用ContactsContract.Contacts.Photo获取指定联系人的照片。
上述文档链接中的完整示例:
public InputStream openDisplayPhoto(long contactId) {
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
try {
AssetFileDescriptor fd =
getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");
return fd.createInputStream();
} catch (IOException e) {
return null;
}
}
关于java - 如何获取联系人的照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8968687/