在图像捕获意图中添加额外的文件路径会导致相机应用程序在 TF300t Android 平板电脑(具有库存系统版本 4.2.1)上出现故障。按“完成”按钮没有任何作用——甚至没有关闭相机应用程序活动。不返回任何结果。
我使用的代码是从Adroid 开发者网站中提取的
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imageFile = createImageFile();
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
startActivityForResult(cameraIntent, THIS_CAMERA_REQUEST);
将createImageFile()定义为:
private File createImageFile() throws IOException {
File outputDir = getBaseContext().getCacheDir();
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "photo_" + timeStamp + "_";
File image = new File(outputDir, imageFileName);
return image;
}
当线
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
被删除,相机应用程序按预期运行。
有没有合理的解决方法?我宁愿不自己构建相机应用程序只是为了拍照。