Open Gallery in a Specific Directory - android

I'm trying to open all the photos taken with my app using the native Gallery.
Here is my code:
Intent intentBrowseFiles = new Intent(Intent.ACTION_VIEW);
intentBrowseFiles.setType("image/*");
Uri uri = Uri.parse(Environment.getExternalStorageDirectory() + "/DCIM/MyApp");
intentBrowseFiles.setData(uri);
intentBrowseFiles.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentBrowseFiles);
If I don't set the setData the gallery opens, but in the root, if I set, my app crashes.
Is there a way to open it in the Gallery in a specific directory?
Anyway, thank you!

Related

How to use an Image Uri outside Activity?

I'm creating a Sign-Up page from my app that has the option to obtain an image from the gallery using this code:
Intent pickImageFileIntent = new Intent(Intent.ACTION_PICK);
pickImageFileIntent.setType("image/*");
String pickTitle = getString(R.string.select_img_gallery);
Intent chooserIntent = Intent.createChooser(pickImageFileIntent, pickTitle);
startActivityForResult(chooserIntent, PICK_IMAGE);
After the user selects the image from the gallery I show that image in an ImageView using Glide, and it works fine. But when I try to use that image's Uri in another activity I get permission denied and the app crashes, so I think the Uri only has permissions for the Activity where ti was obtained. I tried to use ACTION_GET_DOCUMENT instead of ACTION_PICK and it works but the problems is in the Intent chooser it only shows the file explorer instead of the default media gallery and Google Photos, like when I use ACTION_PICK. Is there a way to use the Uri outside the activity while still using ACTION_PICK?

Opening image with Intent through absolute file path

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!
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 */

Cannot Show images with gallery app in android

I want open my images with gallery app but show this error
Cannot generate thumbnail
my code:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/Connection/Picture/"+listItems.get(position)), "image/*");
startActivity(intent);
Is there another way to show image with default android app?
Notice:
1.when I use a file manager to open it , it open successfully
2.when I use my app to open image ,if I choose another app to open it,it open successfully
3."listItems.get(position)" is imagename forexample "2361386837.jpg"
Can You help me?

Displaying Images in Gallery and sharing them

My application is capable of capturing images and saving them (in the public Pictures directory, retrieved by Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).
Now, I want to be able to display those images in the system's gallery application. In order to achieve that, I create an Intent like this (filePath is a String containing the image's path):
Intent viewIntent = new Intent();
viewIntent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(filePath));
viewIntent.setDataAndType(uri, "image/jpeg");
startActivity(Intent.createChooser(viewIntent, null));
Displaying an image this way works perfectly fine, but the gallery's Share functionality doesn't seem to work:
When I press the Share-button, I get to choose the app I want to share to; but once I select it, nothing happens, as if the target application does not receive any data.
Is there any explanation why this behaviour occurs and how it can be fixed?
Edit: I used Intent Intercept to capture the Intent created by the Gallery/Photos app:

How to open image with uri like "content://" in default gallery app?

In my app I select an image from gallery. After, when the user click on it, I want to open the image with an app that handle images.
In android kitkat 4.4 I have a "content://" uri. When I try this code:
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
intent.setDataAndType(uri,"image/*");
startActivity(intent);
The gallery app doesn't show me the image but a blank screen with an error message.
How can I open this kind of Uri with an intent?

Categories

Resources