How to close default gallery programmatically? - android

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.

Related

Start Android gallery app without specifying or picking image

How can we start the gallery app in Android without telling it which file to display?
This is because I want to show images in an album/folder. However, I understand there is no such function. So, I would like to just start the gallery app.
ACTION_VIEW will always result in an "unsupported file" message, if there is no URI specified, or if MediaStore.Images.Media.EXTERNAL_CONTENT_URI is specified. This is bearable, but not desirable, as it tells the user something is wrong with my app.
ACTION_PICK works partially, but the later half is not what I want. I want the user to choose images, and see the chosen images in the gallery. The gallery should not return the URI to my app, and expect my app to display it. There is a reason for this, that is, I want the user to be able to switch from one image to another without returning to my app. The user should return only after he/she has decided not to view anymore image.
The code that I have tried :
intent = new Intent (Intent.ACTION_VIEW);
intent.setType ("image/*");
startActivity (intent);
intent = new Intent (Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivity (intent);
Any suggestion?

Reading gallery folders using Implicit intent

I am implementing an android app, which will synchronize images from selected folder to server (as Google Photo). I want that user will select folder by clicking on button. I can achieve this by creating my own view. But, if implicit intent can any implicit intent action by which I can show user only images folder from device?
Try,
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 100);
change EXTERNAL_CONTENT_URI constant accordingly.

Android Xamarin - App Closes when using image gallery picker

I have an activity that opens the image picker. When starting the gallery the selection intent opens and you are able to choose a photo, this works sometime and on some devices but other times does not work and closes the Activity instead of calling OnActivityResult (The application appears to be backgrounded, but upon reopening the application restarts)
When it does succeed everything works as expected.
I have tried this:
Button menu_upload = menu.FindViewById<Button>(Resource.Id.menu_upload);
menu_upload.Click += (o, e) =>
{
var imageIntent = new Intent();
imageIntent.SetType("image/*");
imageIntent.PutExtra(Intent.ExtraAllowMultiple, true);
imageIntent.SetAction(Intent.ActionPick);
StartActivityForResult(Intent.CreateChooser(imageIntent, "Select Image"), REQUEST_IMAGE_CAPTURE_MULTI);
// ALSO TRIED THIS WITH SAME RESULT
/*var imageIntent = new Intent();
imageIntent.SetType("image/*");
imageIntent.SetAction(Intent.ActionGetContent);
StartActivityForResult(
Intent.CreateChooser(imageIntent, "Select photo"), REQUEST_IMAGE_CAPTURE_MULTI);*/
};
It seems looks like the activity is being destroyed when it's backgrounded. How do I do this correctly? Or How do I get the chooser to resume to my activity after the image has been chosen?
I have checked out the other articles on this topic but I am unable to get anything to work.
The activity that was attempting to launch the picker was launched with an android:noHistory flag set. This means that when the picker is launched and the parent activity is no longer on the screen it is closed by Andriod.
More info can be found in the official documentation here:
Official Android Activity Documentation

Open camera app with a thunbnail icon

I want to launch Android built-in camera app with a thumbnail icon on the right-bottom. Here is my code to open the camera app.
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I think I need to put a intent data to do it. I look forward to your help.
Thanks.
Just create an image button, or button or anything you desire really.
In the onclick event add something like:
String saveFileName= Environment.getExternalStorageDirectory() + "/test.png";
// BUILT IN CAMERA
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(saveFileName) );
this.startActivityForResult(camera, 1);
Make sure you have necessary permissions set. Like saving to the SDCard.
You are very close, you dont need those flags set. And you should ideally specify where you are saving the image.
If you are wondering how to make the button take a look here

Pick an image from the Gallery

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);

Categories

Resources