I have seen a lot of posts about this, and it seems like the code below should work. I have created an SD Card image and added it to the emulator (and that works fine).
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
//intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 1);
It does launch and allow selection of images, but when I click on an image, everything exits and the emulator returns to the home screen, not the back to my app. My onActivityResult is never called either.
What am I missing?
I found my issue. I was launching the gallery from a sub-activity and that sub activity Intent had the flag FLAG_ACTIVITY_NO_HISTORY which prevented the call back from going to that activity.
thanks.
Use the following intent :
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("return-data", true);
startActivityForResult(intent, 1);
Related
I need to get the path of the result image path from intent without using the onActivityResult.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
I need the path of the image to the next step in OnCreate which is after the this intent started. Is there any way to get this done without using OnActivityResult ??
I need the path of the image to the next step in OnCreate which is after the this intent started
That is not possible. startActivityForResult() does not even begin doing its work until after your current callback (onCreate(), apparently) returns.
Is there any way to get this done without using OnActivityResult ?
No.
I need the result image path to pass it to a new method and start a new intent.
Do that in onActivityResult().
this intent can be only created inside the onCreate due to my application structure
That seems unlikely. Even if for some bizarre reason it is true, create the base Intent in onCreate(), store it in a field of your activity, and use the Intent in onActivityResult().
I am using this code
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
photoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
photoPickerIntent.addCategory(Intent.CATEGORY_OPENABLE);
photoPickerIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(photoPickerIntent, "Image File Picker"), 1000);
to pick image from sdcard within my application.
this is working fine, according to my requirement i need to close that ACTION_PICK chooserActivity myself, like when we touch outside the dialog that will closed fine...
but how can we close this type of dialog programmatically?
You can't.
That chooser is actually a separate activity, launched by intent (which will then launch another activity via intent when the user selects something).
You don't control that chooser, its not actually in your app.
In "developer options" settings I use "don't keep activities" mode. I need pick image from gallery and use its URI in my application.
The code which opens the gallery in order to pick image is:
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType(FileType.IMAGE);
startActivityForResult(intent, 1);
The issue happens when I pick image. "Please wait..." message is shown and then I turned back to the "select image" in gallery.
It happens in HTC One X device when this mode is turned on. In Samsung Galaxy S3 this issue doesn't occur.
How can I solve it on HTC ONE X device when this mode is on?
Try this
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
The 1 is the request code passed to the activity to differentiate multiple activities called.
I switched to Intent.ACTION_GET_CONTENT with just mime-type and it seems to work better. I guess an HTC bug.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
I am building an application and in one of my activities, I am displaying some information from a database and one image, this image is scaled down and when the user press the image, I am launching the built-in gallery to view it in a larger size.
My problem here is the following
when I am done looking at the image in the gallery, I want the user when he press the back button to go back to my app and exactly to the activity that launches the gallery, my application show me a crash message and direct me to the main activity of my app
here is the code that launches the built-in gallery
imageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new
File(image_file.getAbsolutePath())),"image/*");
startActivityForResult(intent, 1);
}
});
I tried using startActivity(intent);
but that still not working.
I also tried to override onPuase() and onResume()
but after I did, the entire activity that hold the imageView does not launch and the app crashes.
when I looked up something similar to this problem, people say that I may have bad manifest but I am doing nothing for that Activity in my manifest.
How can I fix the problem so the user can see the image in the built-in or any other gallery app then presses the back button to go back to my app?
thanks
I am not sure but try below code in your on click listener
imageView.setOnClickListener(new View.OnClickListener() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
}
});
When using the following code to select a picture from my gallery, I also have the option to take a new picture, when I do it saves it (in the default image gallery) and I can select that image.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select Picture"),
PICK_IMAGE);
My ultimate goal is to have two options "select from gallery" and "take picture". My question - is there a way to boot the camera automatically via the above Intent, possibly with some extras?
And I don't mean using the camera intent:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
While testing with the camera intent I have been running into two main bugs: Ok button bug and the small image return, so I was wondering if my other method is possible. Probably not, but its worth a shot..?
As far as I know, the answer is no. The best method is getting the Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); to play nicely. Even if it were possible, the user interaction would be unintuitive and confusing as there would be no "accept photo" button/interaction.