我该如何在Android 4.3中使用intent调用相机应用来捕获视频?在4.2及以下版本中,我已经成功实现了此功能。甚至Google的示例代码也失效了。这是一个bug吗?还是Google改变了返回记录视频的方式?图像捕获仍然有效。虽然我仍然可以收到RESULT_OK,但MediaStore.ACTION_VIDEO_CAPTURE意图的数据为空。
是的,从Android 4.3版本开始就存在bug。
正如文档所说:
如果没有提供EXTRA_OUTPUT,则视频将被写入标准视频位置,并且该位置的Uri将在Uri的数据字段中返回。
我的经验是,返回的数据字段值为Null
,而不是包含视频文件的Uri
。
目前的解决方法是,如果设备的API版本为18,则将MediaStore.EXTRA_OUTPUT
传递给Intent
,指定视频文件的输出位置。这样可以正常工作。
由于您使用默认的图库位置存储视频,因此我猜您想保持不变。因此,您需要将EXTRA_OUTPUT
设置如下。
Insert a new record into MediaStore.Video.Media.EXTERNAL_CONTENT_URI:
Uri videoUri = context.getContentResolver().insert(EXTERNAL_CONTENT_URI, value);
Being value
a ContentValues
with display name, file type and file path to the new video file. E.g. :
ContentValues value = new ContentValues();
value.put(MediaStore.Video.Media.TITLE, "VideoTitle");
value.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
value.put(MediaStore.Video.Media.DATA, videoFilePath);
Pass the returned value, videoUri
, as the EXTRA_OUPUT
to the Intent
.