从谷歌播放服务API调用配置文件图像网址时出错

时间:2013-12-18 11:54:48

标签: android google-play google-play-services google-play-games

我想使用google play service api获取google plus个人资料图片。 我使用了ImageManager.loadImage。

但我错了。 检查here

此错误已修复但我是。

我的代码就是这样......

ImageManager im = ImageManager.create(getApplicationContext());                 
im.loadImage(new ImageManager.OnImageLoadedListener(){
@Override
public void onImageLoaded(Uri uri, Drawable drawable){
    Log.i("TAG", "please....");
}}, getGamesClient().getCurrentPlayer().getIconImageUri());

我的错误报告就像这样。

12-18 20:38:07.505: E/AndroidRuntime(15150): FATAL EXCEPTION: main
12-18 20:38:07.505: E/AndroidRuntime(15150): java.lang.RuntimeException: Unable to start receiver com.google.android.gms.common.images.ImageBroadcastReceiver: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.gms.common.images.ImageManager$b
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2244)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.app.ActivityThread.access$1500(ActivityThread.java:138)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.os.Looper.loop(Looper.java:137)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.app.ActivityThread.main(ActivityThread.java:4870)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at java.lang.reflect.Method.invokeNative(Native Method)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at java.lang.reflect.Method.invoke(Method.java:511)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at dalvik.system.NativeStart.main(Native Method)
12-18 20:38:07.505: E/AndroidRuntime(15150): Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.gms.common.images.ImageManager$b
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.os.Parcel.readParcelable(Parcel.java:2077)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.os.Parcel.readValue(Parcel.java:1965)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.os.Parcel.readMapInternal(Parcel.java:2226)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.os.Bundle.unparcel(Bundle.java:223)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.os.Bundle.getParcelable(Bundle.java:1165)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.content.Intent.getParcelableExtra(Intent.java:4226)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at com.google.android.gms.common.images.ImageBroadcastReceiver.onReceive(SourceFile:21)
12-18 20:38:07.505: E/AndroidRuntime(15150):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2237)
12-18 20:38:07.505: E/AndroidRuntime(15150):    ... 10 more

2 个答案:

答案 0 :(得分:2)

我在我的项目中将此代码用于相同的

ImageView player1IV = (ImageView) findViewById(R.id.iv_player_1_fs);
    ImageView player2IV = (ImageView) findViewById(R.id.iv_player_2_fs);
    TextView p1Name = (TextView) findViewById(R.id.tv_player_1_fs);
    TextView p2Name = (TextView) findViewById(R.id.tv_player_2_fs);

    ImageManager imageManager = ImageManager.create(getApplicationContext());
    if (mRoomId != null) {
        MyLog.printLog("mRoomId :" + mRoomId + getGamesClient().toString());
        for (Participant p : mParticipants) {
            String pid = p.getParticipantId();

            if (pid.equals(mMyId)) {
                MyLog.printLog("p.getIconImageUri()) :" + p.getIconImageUri());
                MyLog.printLog("p.getHiResImageUri() :" + p.getHiResImageUri());

                imageManager.loadImage(player1IV, p.getIconImageUri(), R.drawable.stub);
                p1Name.setText(p.getDisplayName());

                continue;
            } else {
                imageManager.loadImage(player2IV, p.getIconImageUri(), R.drawable.stub);
                p2Name.setText(p.getDisplayName());
            }
        }
    } else {
        // load image
        try {
            InputStream inputStream = getAssets().open("pp/" + mRoboticPlayer.getName() + ".jpg");
            Drawable d = Drawable.createFromStream(inputStream, null);
            player2IV.setImageDrawable(d);
        } catch (Exception e) {
            e.printStackTrace();
            imageManager.loadImage(player2IV, R.drawable.stub);
        }
        p2Name.setText(mRoboticPlayer.getName());

    }

答案 1 :(得分:-1)

这看起来像是一个Proguard问题。 Google Play游戏库正在变得模糊,因此无法在运行时找到必要的类。尝试将AndroidManifest.xml上的目标API级别设置为17或更高(这会更改Proguard的行为)并查看是否可以解决问题:

<uses-sdk android:minSdkVersion="9"
      android:targetSdkVersion="17" />