** * 录像 */ public void video(View v){ //创建意图对象 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); //设置录像的存储位置 File file = new File("/mnt/sdcard/luxing.mp4"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); // set the image file name //设置录像质量 intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high // start the Video Capture Intent startActivityForResult(intent, 2); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (data == null) { return; } switch (requestCode) { case 1: Toast.makeText(this, "拍照成功 /mnt/sdcard/zanmen.jpg", 0).show(); break; case 2: Toast.makeText(this, "录像成功 /mnt/sdcard/luxiang.mp4", 0).show(); break; default: break; } }
添加权限: <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />