In Android, How to obtain Uri of image on SD-Card

How to get URI of image stored on SD-Card?

Step 1:- Read the image from SD-Card.
[java]File sdCardDir = Environment.getExternalStorageDirectory();
File yourFile = new File(sdCardDir, “path/to/the/file/filename.ext”);[/java]

Step 2:- Once you get object of image file, you can get URI of the image.
[java]Uri imageUri = yourFile.toUri();[/java]

Next:-
You ready to use URI wherever you want. Below e.g. shows we can use it to start intent for the same image.
[java]Intent intent = new Intent(Intent.ACTION_VIEW, imageUri);
startActivity(intent);[/java]
Not very tough, but love sharing this stuff.

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.