【发布时间】:2013-08-01 09:28:54
【问题描述】:
我正在编写一个 SMS 消息应用程序,我想显示所有发件人的个人资料图片(这不是问题)和我的个人资料图片以用于发送的消息。在本机消息传递应用程序中完成了相同的实现。 您能否建议我如何获得自己的头像?
【问题讨论】:
标签: android sms messaging user-profile
我正在编写一个 SMS 消息应用程序,我想显示所有发件人的个人资料图片(这不是问题)和我的个人资料图片以用于发送的消息。在本机消息传递应用程序中完成了相同的实现。 您能否建议我如何获得自己的头像?
【问题讨论】:
标签: android sms messaging user-profile
我为我的问题找到了解决方案:
public static Bitmap getProfilePhoto(Context context) {
Bitmap profilePhoto = null;
ContentResolver cr = context.getContentResolver();
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, ContactsContract.Profile.CONTENT_URI);
if (input != null) {
profilePhoto = BitmapFactory.decodeStream(input);
} else {
profilePhoto = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_contact_picture);
}
return profilePhoto;
}
【讨论】:
在这里阅读 http://developer.android.com/reference/android/provider/ContactsContract.Profile.html 然后 查看CursorLoader's 和cursors,写一个来查询照片uri或照片缩略图uri。
更新
我发现了应该对您有所帮助的类似问题
Get profile picture of specific phone number from contacts information
Get user/owner profile contact URI and user image with API 8 onwards
【讨论】:
ContactsContract.Profile API