I am using the ACTION_EDIT intent to launch the Android image editor in order to edit an image:
Intent editIntent = new Intent(Intent.ACTION_EDIT);
editIntent.setDataAndType(uri, "image/*");
When launching the intent with result, how do I retrieve the path of the edited / saved image?
I am using the ACTION_EDIT intent to launch the Android image editor in order to edit an image
Bear in mind that Android does not have an image editor. Some Android devices might ship with an image editor, and some users may have installed an image editor off of the Play Store or other distribution channels.
Also, since you know what the MIME type is of uri, you will have better results if you put the real MIME type into your Intent.
When launching the intent with result, how do I retrieve the path of the edited / saved image?
First, ACTION_EDIT does not support "launch the intent with result", which I am interpreting as meaning startActivityForResult(). As the ACTION_EDIT documentation states, there is no output. Just use startActivity().
Beyond that, you are the one who provided the Uri in the Intent for the editor, so at that point in time, you already knew what the Uri was that you handed to the editor. Hang onto that Uri in your saved instance state, so that you can ensure that you have the Uri even if Android terminates your process while the user is editing the image. While there is no requirement that an ACTION_EDIT Intent save the edited image back to the location specified by the Uri used to load the image, one hopes that most ACTION_EDIT activities do just that.
Related
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.
i have a little problem, I need show the images/videos form a specific folder via default gallery, but when i throw the intent, the gallery not shows only files from the folder that i pass to te data intent, the gallery shows all images to the device. The code that i use is:
Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory().toString() + "/DCIM/folder/");
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setData(selectedUri);
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I need show the images/videos form a specific folder via default gallery
That is not possible. There are thousands of device models. These ship with hundreds of different "default gallery" apps. None of them have to have some sort of API to allow you to request that they view some directory's worth of images.
Activities responding to ACTION_VIEW with a MIME type of image/* will expect that the Uri points to a single image. There is no MIME type for a directory, and there is no requirement that any gallery app honor such a MIME type even if one existed.
As the title suggests, i'm having an option to upload an image in my app.
I would like to have two options: Click a new picture & Select from gallery.
Gallery selection is working fine on all devices using this code:
Intent in = new Intent();
in.setType("image/*");
in.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(in, getString(R.string.selectpicture)), 100);
The problem is with Click a new picture.
I want to use other camera apps installed on the device to get the image.
This code should save the image user clicks at the specified path.
Intent m_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = getImageUri();
m_intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(m_intent, REQUEST_IMAGE_CAPTURE);
But what happens is, the EXTRA_OUTPUT is not respected by all camera apps.
Also if memory is low, my app is killed by the system which makes things more complicated.
So, what's the best way to enable user to click a new picture and get the image path in my app?
If using third party libraries is better, which one's are reliable?
the EXTRA_OUTPUT is not respected by all camera apps.
Any time you delegate anything to a third party app, you can run into problems.
Also if memory is low, my app is killed by the system which makes things more complicated.
You need to handle this anyway. Save the value you put in EXTRA_OUTPUT in the saved instance state Bundle.
what's the best way to enable user to click a new picture and get the image path in my app?
If you wish to stick with ACTION_IMAGE_CAPTURE, I'd go with this triage:
If there is an image in the location you provided to EXTRA_OUTPUT, use it
If not, and getData() on the Intent given to you in onActivityResult() returns a Uri (and not null), use that (and if you truly need a File, use ContentResolver and openInputStream() with the Uri and copy the contents into your own file)
If neither are true, and getParcelableExtra("data") returns a value, save that Bitmap to a file
If none of those are true, suggest to the user to get a different camera app, perhaps pointing them to one that you have tried and know works
Or, take the picture yourself, directly or using a library like mine.
I'm writing an app that uses the camera. I want to lauch an intent to allow users to annotate the resulting image with lines and text, AND I would like to provide the user with a list of appropriate image editting apps they can use, but I'm coming across these problems:
1. Not all image editting apps appear in the list when I perform this code:
editIntent = new Intent();
editIntent.setAction(Intent.ACTION_EDIT);
Uri imageToEditUri = selectedPhotoLocation; // Uri of existing photo
String imageToEditMimeType = "image/*";
editIntent.setDataAndType(imageToEditUri, imageToEditMimeType);
startActivityForResult(Intent.createChooser(editIntent,"Edit Image"), IMPLICIT_EDIT_IMAGE);
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
2. PS Express is the only app I've found that returns the Uri of the editted image in the data.getDate() Uri returned to OnActivityResult(), with other apps the user is forced to save, remember the location, and reselect the editted image.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
Not all image editting apps appear in the list when I perform this code
Just because an app implements image editing does not necessarily mean that it is set up to allow third parties to link to their image-editing activities.
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
If you mean that you want to do this programmatically at runtime, see Jedil's answer.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
No, except for those applications that have documentation on how developers should integrate with them.
First question answer:
try queryIntentActivities
Intent editIntent = new Intent(android.content.Intent.ACTION_EDIT);
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(editIntent, 0);
I'm trying to use a standard Intent that will take a picture, then allow approval or retake. Then I want to save the picture into a file.
Here's the Intent I am using:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult( intent, 22 );
The documentation says:
The caller may pass an extra EXTRA_OUTPUT to control where this
image will be written. If the EXTRA_OUTPUT is not present, then a
small sized image is returned as a Bitmap object in the extra field. If
the EXTRA_OUTPUT is present, then the full-sized image will be
written to the Uri value of EXTRA_OUTPUT.
I don't pass extra output, I hope to get a Bitmap object in the extra field of the Intent passed into onActivityResult() (for this request). So where/how do you extract it? Intent has a getExtras(), but that returns a Bundle, and Bundle wants a key string to give you something back.
What do you invoke on the Intent to extract the bitmap?
Try calling getExtras().get("data") and casting the result to a Bitmap.
See here for an example.
On a related note, if you have the "crop" activity come up after taking the picture using intent.putExtra("crop", "true"), you'll get the cropped URI from getExtras().get("action").
I realize you've got this all fixed by now, just want to make sure no one tries to use this with crop and gets confused.
Reference: the apps-for-android LolCat activity.