Android gms ImageManager 从不加载图像

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

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

方法/问题:

  • 图片的URI成功获取,存在且有效。
  • 我使用 ImageManager.loadImage 获取图像,使用 OnImageLoadedListener 进行回调(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);

最佳答案

这可能是一个很晚的答案,但它可能会帮助其他有同样经历的人。来自最新的谷歌文档,https://developers.google.com/android/reference/com/google/android/gms/common/images/ImageManager.html#public-methods

Note that you should hold a reference to the listener provided until the callback is complete. For this reason, the use of anonymous implementations is discouraged.

这可能解释了您遇到的行为,因为在提供的第一个代码 fragment 中,没有保留对 Listener 的引用。

关于Android gms ImageManager 从不加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25874203/

相关文章:

android - 是否预计应用强制停止 InstanceId 更改?

android - SQLite 异常 : Unrecognized token when reading from database

android - 从 BroadcastRecevier 启动 AlertDialog 时在后台显示当前 Activity

android - Android 代码示例入门 - 权限错误

java - 使用 Java 获取 Internet 文件并将其创建为 File 对象?

android - Gradle 错误 : Unexpected inputs: android. gms:play-services

android - 如何提高位图质量?

io - 通过 ynot 在 Coq 中进行文件 I/O

c - 用C打开文件时出现段错误

Android:Google+ 整合。在仍然连接的情况下调用 connect(),缺少 disconnect()