【问题标题】:Android: how to get own profile picture like in native Messaging appAndroid:如何在原生消息应用程序中获取自己的个人资料图片
【发布时间】:2013-08-01 09:28:54
【问题描述】:

我正在编写一个 SMS 消息应用程序,我想显示所有发件人的个人资料图片(这不是问题)和我的个人资料图片以用于发送的消息。在本机消息传递应用程序中完成了相同的实现。 您能否建议我如何获得自己的头像?

【问题讨论】:

    标签: android sms messaging user-profile


    【解决方案1】:

    我为我的问题找到了解决方案:

    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;
        }
    

    【讨论】:

    • 有效,我建议在 openContactPhoto 中使用“true”以获得高分辨率;) InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, ContactsContract.Profile.CONTENT_URI,true);
    【解决方案2】:

    【讨论】:

    • 感谢您的信息,我使用了ContactsContract.Profile API
    猜你喜欢
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-20
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    相关资源
    最近更新 更多