找到getUnlockedImageUri的本地路径

时间:2016-03-07 06:08:10

标签: java android google-play-services

我可以使用URI方法ImageManager中的getUnlockedImageUri显示成就图片但由于某些原因,我需要找到图片的本地路径,因为我不想使用ImageView,我需要图像的实际文件路径

Google Play游戏成就的URI看起来像这样content://com.google.android.gms.games.background/images/d2bbfba4/61,我希望能够将其转换为File对象,如下所示:

File myFile = new File(ach.getUnlockedImageUri().getPath());
Log.i(ExConsts.TAG, "myFile.exists() = " + myFile.exists());
// returns false!

但这不起作用!任何想法为什么?或者我应该尝试什么?或者甚至告诉我它是否可能?

1 个答案:

答案 0 :(得分:0)

content:// Uri是一个明确的标志,

  • 没有本地文件
  • 您无法直接访问本地文件

getRevealedImageUri() Javadoc中所述:

  

要从Uri检索图像,请使用ImageManager

您可以使用ImageLoader.loadImage(OnImageLoadedListener, Uri)获取DrawableCanvas可以使用Drawable.draw(Canvas)Drawable上绘制。

如果您愿意,可以使用与this answer类似的内容将Bitmap转换为var itemText = document.getElementById("item_", + boxId);