1

I am new to android development.

I am trying to open the default gallery app to view an image like this:

 Uri u = Uri.parse((String) gridView.getAdapter().getItem(position);
 Intent i = new Intent();
 i.setDataAndType(u, "image/*");
 i.setAction(Intent.ACTION_VIEW);
 i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
 startActivity(i);

I provide the file paths to my images like this:

/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20191023-WA0045.jpg

/storage/emulated/0/Pictures/9GAG/1565987862000.jpg

My App and Google Photos can display the image given this path, the Samsung Gallery( tested on Android Oreo) or the Xiaomi Gallery App (tested on Android X) can't find the image; also if i try to add "content://" or "file://" at the beginning. I suspect that the apps want to have a Content URI or some kind of symbolic link without the "/storage/emulated/0/" part instead of a File URI. I searched for methods to get the content URI out of the file path, but didn't find any examples for Android X.

So what is the correct URI to pass on through the Intent and how do i get it?

Or maybe somebody knows a better way to just open the gallery app to a specific picture i provide by an absolute file path (Both External Storage and SD Card)?

Thank you in advance and greetings!

Mamsie
  • 11
  • 1

1 Answers1

0

copied from this question here , this might work for you startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16"))); /** replace with your own uri */

Remon Shehatta
  • 1,324
  • 1
  • 10
  • 21
  • This indeed works, but it is sadly no option do hardcode the path in my program, since the images change frequently and are located in different directories. I got it to work using file provider, but the gallery app then thinks it's a new picture and only gives me the option so save instead of the regular options :/ – Mamsie Apr 26 '20 at 10:35