0

I am able to show achievement images using the ImageManager from the URI method getUnlockedImageUri but for some reasons, I need to find the local path to the image because I don't want to use the ImageView and I need the actual file path to the image

The URI of Google Play Games achievement looks something like this content://com.google.android.gms.games.background/images/d2bbfba4/61 and I was hoping to be able to convert it to a File object like below:

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

But that does not work! any idea why? or what else I should try? or even tell me if it's possible?

Hadi tavakoli
  • 1,267
  • 2
  • 16
  • 30

1 Answers1

0

A content:// Uri is a clear sign that either

  • There is no local file
  • You do not have direct access to the local file

As stated in the getRevealedImageUri() Javadoc:

To retrieve the Image from the Uri, use ImageManager.

You can use ImageLoader.loadImage(OnImageLoadedListener, Uri) to get a Drawable which can be drawn onto a Canvas using Drawable.draw(Canvas).

You can convert a Drawable to a Bitmap using something similar to this answer if you'd like.

Community
  • 1
  • 1
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443