MOckjer
MOckjer

Reputation: 621

Displaying an image in gallery intent

Is there any way to create an intent that will open that gallery and will show a specific image in there? I'm not asking about saving the image to the memory but I just want a proper and easy way to show the image (not in an ImageView) in such a way that zooming will be available.

Upvotes: 0

Views: 41

Answers (1)

Jack
Jack

Reputation: 5614

You can use Intent and ACTION_VIEW to achieve that:

Intent intent = new Intent();  
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.parse("file://" + "YOUR_FILE's PATH");
//Or you can use                 
Uri uri = Uri.fromFile(new File("YOUR_FILE's PATH"));
intent.setDataAndType(uri,"image/*");
startActivity(intent);

If you're targeting or the device is API level 24+, refer to this answer to see how to get the proper Intent and avoid FileUriExposedException

Upvotes: 1

Related Questions