第一步:

在清单文件中添加 <uses-feature> 代码:

  <manifest ... >
        <uses-feature android:name="android.hardware.camera"
                      android:required="true" />
        ...
    </manifest>

第二步:

调用 Intent 以拍摄视频的函数

 static final int REQUEST_VIDEO_CAPTURE = 1;

    private void dispatchTakeVideoIntent() {
        Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
        }
    }

第三步录制完成后,返回获取到视频的uri

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
            Uri videoUri = intent.getData();
           
        }
    }
    

 

注意,记得动态申请权限:CAMERA和WRITE_EXTERNAL_STORAGE

 

相关文章:

  • 2022-02-07
  • 2021-06-18
  • 2022-01-17
  • 2021-11-26
  • 2022-12-23
  • 2021-09-27
  • 2021-12-04
  • 2021-06-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2022-01-12
相关资源
相似解决方案