【问题标题】:Google Plus Profile Picture Google Play Game ServicesGoogle Plus 个人资料图片 Google Play 游戏服务
【发布时间】:2013-09-02 19:58:19
【问题描述】:

我已经看过这个论坛的所有帖子,但我没有找到任何东西。 如何在 ImageView 中显示登录我的应用程序的 google plus 的个人资料图片?与图像管理器? 你能显示一些代码吗?

【问题讨论】:

    标签: eclipse google-plus google-play-games


    【解决方案1】:

    下面的方法可以满足你的要求。

    public class AvatarImage extends ImageView  {
        Bitmap image;
        public static final String TAG = "AvatarImage";
    
        public AvatarImage(Context context) {
            super(context);
            setImageResource(R.drawable.avatar);
        }
    
        /**
         * This method takes the participant object and attempts to 
         * download avatar of the participant from google plus
         * if this is unsuccesful default avatar is shown
         * @param p
         */
        public void setImageFromParticipant(Participant p) {
            ImageManager im = ImageManager.create(getContext());    
            im.loadImage(this, p.getIconImageUri(), R.drawable.avatar);
            try{
                Bitmap bitmap = ((BitmapDrawable)this.getDrawable()).getBitmap();
                setImageBitmap(bitmap);
            }
            catch(NullPointerException e)
            {
                 e.printStackTrace();
            }
        }
    }
    

    【讨论】:

    • 对不起。这很简单,对我有用。如果您在将其集成到您的代码时遇到问题,您应该更具体地说明它是如何工作的。以便我能提供帮助。
    • ImageHelper 是我自己的课程。以上不是复制粘贴代码;你应该省略我正在编辑答案的那一行
    • 这是我运行应用程序时显示的 logcat:09-08 17:20:47.560: E/AndroidRuntime(27415): FATAL EXCEPTION: main 09-08 17:20:47.560: E /AndroidRuntime(27415):java.lang.RuntimeException:无法启动接收器 com.google.android.gms.common.images.ImageBroadcastReceiver:android.os.BadParcelableException:解组时 ClassNotFoundException:com.google.android.gms.common。 images.ImageManager$c
    • 这是代码: AvatarImage ai = new AvatarImage(this); ai.setImageFromParticipant(getGamesClient().getCurrentPlayer().getIconImageUri()); profile_person.addView(ai); profile_person 是一个 relativeLayout,我用括号上的 uri 更改了 setImageFromParticipant 函数
    • 这是一个已知错误,您必须等待下一次更新。这里是详细信息code.google.com/p/play-games-platform/issues/detail?id=7
    【解决方案2】:

    John 的另一个答案显示的代码是正确的,但是,Google Play 服务库目前存在问题,如Google Issue Tracker 所示,任何使用该库的版本 10(可能还有版本 9.. 版本)的人8 好)。不幸的是,对于这个问题,如果您尝试让 ImageManager 解码 URI,Google Play 服务就会停止工作。要么等待图书馆的下一个版本,要么尝试获得第 8 版。 (我不能把它作为对上面答案的评论,所以不得不用一个新的答案......)

    【讨论】:

    • 我看到了,我确实知道你发生了什么:)
    猜你喜欢
    • 2016-06-17
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 2016-06-24
    • 2014-09-17
    • 2014-09-17
    • 2014-02-02
    相关资源
    最近更新 更多