我正在使用意图
使用相机活动 MediaStore. INTENT_ACTION_STILL_IMAGE_CAMERA with startactivityforresult
但是当我拍摄照片或视频后按后退键时,我得到 resultcode = 0 和 data = null 。
任何帮助将不胜感激。
答案 0 :(得分:1)
您是否尝试使用MediaStore.ACTION_IMAGE_CAPTURE?它对我有用。我可以拍照并获取URI。这是代码
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String fileName = TravellerUtils.generateUniqueID()
+ IMAGE_FILE_EXT;
File file = new File(Environment.getExternalStorageDirectory(),
TravellerConstants.IMAGE_PATH + fileName);
Uri outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
答案 1 :(得分:1)
此意图MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA允许您拍摄多张照片并将其发送到图库,但是,拍摄后无法捕捉到它。它还允许您拍摄视频,但您无法拍摄。
我建议你分别用两种意图拍摄照片和视频。
for Picture:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Camera");
imagesFolder.mkdirs();
Random random = new Random();
int n = random.nextInt(10000);
File image = new File(imagesFolder, "YourApplication" + n + ".jpg");
photoUri = Uri.fromFile(image);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, Constants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
和视频:
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); // create a file to save the video
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // 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, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);