28

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!

dornad
  • 1,274
  • 3
  • 17
  • 36

3 Answers3

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);
shubham
  • 313
  • 3
  • 7
  • How to get result in this case? – walkmn Jun 29 '18 at 15:10
  • 1
    @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 https://github.com/ChatCamp/ChatCamp-Android-UI-Kit/blob/master/chatkit/src/main/java/com/chatcamp/uikit/messages/sender/CameraAttachmentSender.java – shubham Jul 02 '18 at 06:29
8

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

pallav bohara
  • 6,199
  • 6
  • 24
  • 45
4

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

Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
King of Masses
  • 18,405
  • 4
  • 60
  • 77
Eldo
  • 391
  • 1
  • 7
  • 16
  • `MediaStore.INTENT_ACTION_VIDEO_CAMERA` also can be used. – Nizam Jun 14 '13 at 14:08
  • 11
    How can you retireve the captured image or video on ONactivity result?? – Rakesh Gondaliya Sep 30 '13 at 14:24
  • 4
    This intent won't allow you to retrieve the content captured – Tomer Weller Jun 22 '14 at 11:47
  • @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. – Aniruddha K.M Aug 07 '14 at 09:33
  • 9
    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. – BK- Jan 25 '16 at 20:29
  • @BK- you are right ! any updates regarding this issue ?!! – Muhammed Refaat Oct 30 '17 at 13:06