I find this code here to open the gallery from my own btn:
btnGallery.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 0);
}
});
It works, but when I click on a photo it exit the viewer.
I guess it because the "createChooser".
How can I change it to only view the photos and not to choose them?
As far as I know this is impossible.
If you had access to a full class name of an activity to start the Gallery app you could call it as you usually do it Activity.startActivity(Context context, Class clazz). But Gallery classes is an internal API which you have no direct access to.
Well, Gallery app is accessible via throwing an appropriate Intent like the one in your sample code. By setting action name intent.setAction(Intent.ACTION_GET_CONTENT) you request the behavior you've got (browse all images, select one, get back to the caller activity with a uri of a selected image). There is also another possible action Intent.ACTION_VIEW, and if set with a uri of an image it causes Gallery to show that image for you. But that's all we can request from Gallery (there are no other predefined actions to suit your needs - just to browse images).
So, a way out is to create your own custom image browser activity.
Related
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?
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.
We have a website where on mobile and specifically android devices when people want to change their "avatar" image the options that show up when we click on "upload" does not have the "Gallery". Instead it has "Documents" is there a way to define what to show and what not to show?
We are using PHP if that matters at all for development.
Please see below image.
well it depends on which intent you have used for upload button, in my opinion the most appropriate intent to call when you want user to select an image would be
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
it would make the gallery and other photo handling apps visible in the chooser dialog.
for more information you can go here
Hope it helps
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:
This code successfully retrieves images from the (emulator) SDcard:
public void pickImage(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_IMAGE_GET);
}
}
This returns a bunch of thumbnails titled Choose Picture. Is there any way I can intercept this and filter out certain images first?
Clicking any thumbnail image then runs the OnActivityResult which I can intercept, but then it is too late.
I am using Metadator-extractor and only need to display images containing certain tags, but do not know how to access each
thumbnail before it arrives on the screen.
Is there any way I can intercept this and filter out certain images first?
Not with ACTION_PICK. You are welcome to query MediaStore for available pictures and implement your own pick activity, in which you can filter out whatever you want.