0

I have the absolute path to a .jpg in the gallery. How can I obtain a 'content://' Uri to this image, so that I can use this Uri like this:

Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

I need to launch this intent so I can view the image. How do I obtain the uri, when I have got only the absolute path to the image?

Gabriel
  • 2,054
  • 4
  • 26
  • 34

1 Answers1

1

First you need to read the file from your SDCard.

See:

reading a specific file from sdcard in android

http://developer.android.com/reference/java/io/File.html

File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext");

Then call the File.toUri() method to retreive the URI from the file.

Intent intent = new Intent(Intent.ACTION_VIEW, yourFile.toURI());
startActivity(intent);
Community
  • 1
  • 1
Justin Shield
  • 2,390
  • 16
  • 12
  • 1
    thank you, but it is not working right. First, there is an error, because the second parameter of the Intent() constructor should be android.net.Uri, and it is java.net.URI. Also, the method yourFile.toUri() returns the file:/ URI, while I want the content:// URI. – Gabriel Jul 17 '11 at 22:48