Reputation: 2054
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?
Upvotes: 0
Views: 3221
Reputation: 2380
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);
Upvotes: 1