30

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:

enter image description here

Thanks!

0

3 Answers 3

9

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

Sign up to request clarification or add additional context in comments.

2 Comments

What is contentSelectionIntent ?
@ParasWatts Forgot to add some lines. Please check now.
9

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

2 Comments

How to get result in this case?
@walkmn The result is going to be different for image and video. I am working on an open source library for chat and I have implemented it in that, Please check out this github.com/ChatCamp/ChatCamp-Android-UI-Kit/blob/master/chatkit/…
4

I could capture both image and video by using the below code.

Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); 

6 Comments

MediaStore.INTENT_ACTION_VIDEO_CAMERA also can be used.
How can you retireve the captured image or video on ONactivity result??
This intent won't allow you to retrieve the content captured
@Tomer Weller any idea why the intent won't allow us retrieve the content captured. Is there any way to stop the preview after an image/video is captured and return back to the calling activity.
The Intent parameters ACTION_VIDEO_CAPTURE and ACTION_IMAGE_CAPTURE appear to be specifically designed to launch the camera, capture a piece of media (video or image respectively) and return this. This is typically started with startActivityForResult. Using the INTENT_ACTION_VIDEO_CAMERA parameter simply launches the camera and does not return any result. I don't believe this answers the OP's question.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.