Android Intent for Capturing both Images and Videos?

前端 未结 3 814
陌清茗
陌清茗 2020-12-29 04:15

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.

相关标签:
3条回答
  • 2020-12-29 04:39

    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);
    
    0 讨论(0)
  • 2020-12-29 04:49

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

    Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
    
    0 讨论(0)
  • 2020-12-29 04:57

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

    0 讨论(0)
提交回复
热议问题