提问人:Zain -ul-eman 提问时间:11/13/2023 更新时间:11/13/2023 访问量:14
Camera Intent 始终返回结果代码 0 且 Intent 数据 = null
Camera Intent always return result code 0 and Intent data = null
问:
@Override
public String getFragmentTag() {
return FleetVideoFragment.class.getSimpleName();
}
private void dispatchTakeVideoIntent() {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
takeVideoIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (takeVideoIntent.resolveActivity(mActivity.getPackageManager()) != null) {
File mediaFile = null;
try {
mediaFile = createVideoFile();
} catch (IOException ex) {
// Handle the error
}
if (mediaFile != null) {
Uri uriFile = FileProvider.getUriForFile(mActivity,
"com.tekfirst.practical.fileprovider", // Use your FileProvider authority
mediaFile);
takeVideoIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uriFile);
takeVideoIntent.putExtra(android.provider.MediaStore.EXTRA_DURATION_LIMIT, 60);
takeVideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(takeVideoIntent, REQUEST_CODE_CAMERA);
}
}
}
private File createVideoFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
字符串 videoFileName = “VIDEO_” + timeStamp + “”; 字符串 videoFileName = “VIDEO” + bookedOutRA.getId() + “” + timeStamp + “”; 文件存储Dir = mActivity.getExternalFilesDir(Environment.DIRECTORY_PICTURES); File storageDir = new File(Objects.requireNonNull(mActivity.getExternalFilesDir(Environment.DIRECTORY_PICTURES)).getAbsolutePath(), “/” + bookedOutRA.getId()); 如果 (!storageDir.exists()) { storageDir.mkdirs(); } 文件 video = File.createTempFile( videoFileName, /* 前缀 / “.mp4”, / 后缀 / storageDir / 目录 */ );
// Save a file: path for use with ACTION_VIEW intents
getmCurrentPath = video.getAbsolutePath();
return video;
}
我正在使用默认相机录制视频,但在最新的 android 设备中,其结果总是被取消,但在旧设备中,它可以正常工作。OUTPUT_EXTRA不工作
答: 暂无答案
评论
Intent
ACTION_VIDEO_CAPTURE
ACTION_VIDEO_CAPTURE