In my project I want to let the user pick a picture either from the gallery or take a new one from the camera. Do I need to create my own menu for the user to choose or is there something built into the SDK that does this already?
Use the below code to put chooser for gallery and Camera together. I really dont know if this will work with startActivityForResult. Give it a try
Intent galleryintent = new Intent(Intent.ACTION_GET_CONTENT, null);
galleryintent.setType("image/*");
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Intent chooser = new Intent(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_INTENT, galleryintent);
chooser.putExtra(Intent.EXTRA_TITLE, "title");
Intent[] intentArray = {cameraIntent};
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivity(chooser);
Related
I need to call Intent for image and video both at same time . It seems impossible similar to this . So a alternate way to do this is createChooser() . But i am kinda stuck with the code below .
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, file.getAbsolutePath());
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, file.getAbsolutePath());
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
Intent[] intentArray = new Intent[]{takePictureIntent};
chooserIntent.putExtra(Intent.EXTRA_INTENT, takeVideoIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose an action");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooserIntent, 1);
MediaStore.EXTRA_OUTPUT not working . The file is empty after returning from camera . However it does open a chooser as below but file is empty .
Questions:-
1.How to can i combine both intents and provide separate files as MediaStore.EXTRA_OUTPUT?
2. As we all know there are hundreds of camera apps in android so is this a good way to open such intent(Will it work in all devices regardless of manufacturer and API Level) ? Or i should move with an AlertDialog to open intent for each action seperatly .
Try this below code :
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent chooserIntent = Intent.createChooser(takePictureIntent, "Capture Image or Video");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takeVideoIntent});
startActivityForResult(chooserIntent, CAMERA_IMAGES_REQUEST);
When opening a file picker with the following method:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
Intent chooserIntent = Intent.createChooser(intent, "Open file");
startActivityForResult(chooserIntent, REQUEST_CODE_FILE_PICKER);
unless a default has been set, this will present the user with a choice of file pickers to use. How do you make your own, internal, file chooser available as one of the choices of file pickers presented to the user (such as the Material File Picker)?
Thanks to #CommonsWare's comment, here is the extra bit of code needed to add the internal file picker to the list of choices presented to the user:
// this bit is as before...
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
Intent chooserIntent = Intent.createChooser(intent, "Open file");
// new bit... create Intent for the internal file picker...
Intent materialFilePickerIntent = new Intent(this, FilePickerActivity.class);
materialFilePickerIntent.putExtra(FilePickerActivity.ARG_FILE_FILTER, Pattern.compile(".*\\.txt$"));
// and add the picker to the list...
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { materialFilePickerIntent });
// finally, startActivityForResult() as before...
startActivityForResult(chooserIntent, REQUEST_CODE_FILE_PICKER);
I have Android Xamarin application with imageview
OnClik I lunch intent to preview image
File file = new File(photoPath);
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Uri.FromFile(file), "image/*");
intent.SetFlags(ActivityFlags.NoHistory);
StartActivity(intent);
from apps I choose 'Gallery'
when the image is opend there are no sharing options
when I open image from device 'Gallery' has sharing options
Image is saved to SD card before preview.
what am I doing wrong ?
solution that worked for me
Intent intent = new Intent();
intent.PutExtra(Intent.ActionView, photoPath);
intent.SetType("image/*");
StartActivity(Intent.CreateChooser(intent, "Select Picture"));
now I get my image opend in gallery and I can use sharing options too
Do it using Intent.ACTION_SEND and you'll get that sharing option.
Also try with Intent.ACTION_GET_CONTENT.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), 1);
so I have the code below working fine until android 4.4. I was able to get the path from the uri by intent.getData() in onActivityResult then do something special about the uri to get the path of the photo that was selected.
private Intent createPhotoIntent() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
Intent chooser = createPhotoChooserIntent(createPhotoFromCameraIntent());
chooser.putExtra(Intent.EXTRA_INTENT, intent);
return chooser;
}
private Intent createPhotoChooserIntent(Intent... intents) {
Intent chooser = new Intent(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents);
chooser.putExtra(Intent.EXTRA_TITLE, "Please Choose Your Image");
return chooser;
}
private Intent createPhotoFromCameraIntent() {
return new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
}
what I dont understand is why I'm not able to get anything from intent.getData() now?? I also insert a line break to check what I received from the intent in onActivityResult, and I see nothing related to the path. I was able to see content://media/external/images/media/1249 but not anymore now....what happen to android 4.4!!??
please help.
Is there an Intent for starting a camera with options to capture both Pictures and Videos on Android?
I've used both MediaStore.ACTION_VIDEO_CAPTURE and MediaStore.ACTION_IMAGE_CAPTURE to capture either audio or video, but I can't find an Intent that will get the option for switching between both of them, as in this example app:
Thanks!
It is not possible to capture both image and video using the same intent, Your options are
1) Create your own camera this repo can be a good start But it is going to be a too much effort.
2) Use the Chooser Intent and pass the intent for both image and video, this will give you the option to choose between application which record video and camera separately. In this you cannot do both the things at same time but can choose application according to what you want to do, capture an image or record a video. Below is the code that works for me.
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent chooserIntent = Intent.createChooser(takePictureIntent, "Capture Image or Video");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takeVideoIntent});
startActivityForResult(chooserIntent, CAPTURE_MEDIA_RESULT_CODE);
I achieved it :)
You can do it by following --
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.setType("*/*");
intentArray = new Intent[]{takePictureIntent,takeVideoIntent};
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose an action");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooserIntent, 1);
Similar example here
Happy coding :)
I could capture both image and video by using the below code.
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);