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

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?

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?

Android - how to open image in gallery with delete option

I use following code to open an image in the gallery:
public void onItemClicked(PictureItem item){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri imageUri = FileProvider.getUriForFile(getApplicationContext(), "myapp.fileprovider", new File(item.uri.getPath()));
intent.setDataAndType(imageUri, "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
This shows my photo in the gallery, but in a 'read-only' mode. I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Which action do I have to use for that? I do not want to use pick, just normal view with the option to delete. I tried ACTION_EDIT but it's not supported (and not quite the right choice neither ...).
I use following code to open an image in the gallery
First, there are hundreds, if not thousands, of "gallery" apps available for Android.
Second, your code simply asks to view an image (with a broken Intent due to your wildcard MIME type). There is no requirement for the app that responds to be a "gallery" app.
I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Then implement that yourself, in your own app, and get rid of the ACTION_VIEW Intent.
Which action do I have to use for that?
There is no Intent action that says "please display this image, but only if you are a gallery app, and, oh, by the way, you must offer a delete option", which appears to be what you want.

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:

Open Gallery in a Specific Directory

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!

Categories

Resources