Android gms ImageManager永远不会加载图像

Art*_*shL 2 io android google-play-services google-play-games

我正在尝试使用Google Play游戏服务API为成就绘制一个图标.
然而,它正在默默地失败.

方法/问题:

  • 成功检索图像的URI,存在且有效.
  • ImageManager.loadImage用来获取图像,带有OnImageLoadedListenerfor callback(com.google.android.gms.common.images.ImageManager).
  • 但是从不调用onImageLoadedListener的方法onImageLoaded.
  • 没有错误,没有证据,只是完全被忽略,我甚至等了10分钟以防万一.

码:

// Get URI [is valid, exists, is of type png, I checked]
Uri uri = getAchievementIconUri(id);

// Use ImageManager to get the icon image
ImageManager.create(context).
    loadImage(new ImageManager.OnImageLoadedListener() {

        @Override
        public void onImageLoaded(Uri u, Drawable d, boolean r) {

            /* 
             * This code is never reached, no call to onImageLoaded is made!
             */

        }
}, uri);
Run Code Online (Sandbox Code Playgroud)

小智 5

这可能是一个非常晚的答案,但它可能会帮助其他经历相同的人.从最新的Google文档开始,https://developers.google.com/android/reference/com/google/android/gms/common/images/ImageManager.html#public-methods

请注意,在回调完成之前,您应该保留对提供的侦听器的引用.因此,不鼓励使用匿名实现.

这可能会解释您遇到的行为,如在提供的第一个代码段中,未保留对Listener的引用.