1

在我们的一些游戏中,我在游戏服务实施过程中遇到了困难。我无法检索用户图像(使用 Unity)。我可以获取图像的 Uri(来自内容提供商的 Uri),但我不能使用ImageManager,因为它将数据存储在 a 中imageView,并且我希望图像的 url/path 让 Unity 处理所有数据。

我最好的尝试是设置 aContentResolver但我收到一个安全错误:

许可拒绝:开放提供者com.google.android.gms.games.provider.GamesContentProvider

在这一点上我找不到任何解决方案,事实上我根本找不到任何相关的东西GamesContentProvider。所以我不知道在哪里可以找到检索数据或找到权限的正确方法。

这里有部分代码:

public String getAvatarUrlGame(boolean highRes)
{
    String n = "";
    if (isSignedIn()) {
        Uri uri;
        if(highRes) uri = getGamesClient().getCurrentPlayer().getHiResImageUri();
        else        uri = getGamesClient().getCurrentPlayer().getIconImageUri();

        if (uri != null) 
        {
             Cursor cursor = this.getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
             cursor.moveToFirst();   
             n = cursor.getString(0);
             cursor.close();
         }
    }
    return n;
}

任何帮助将不胜感激。提前致谢!

4

1 回答 1

1

访问图像的唯一方法是通过ImageManager。您不能使用内容解析器。如果您只想要图像并且不想处理 ImageView,您可以使用ImageManager.loadImage(OnImageLoadedListener, Uri),它将调用您的OnImageLoadedListener并使用一个表示图像的 Drawable。

然后,要从 Drawable 中获取与 Unity 兼容的位图,只需将其转换为位图即可。有关如何执行此步骤的信息,请参阅此答案,尤其是安德烈的答案(具有该drawableToBitmap方法的答案)。

希望这可以帮助!

于 2013-05-31T15:38:08.313 回答