ato*_*tok 8 android android-camera
添加文件路径额外的图像捕获意图导致相机应用程序在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);
Run Code Online (Sandbox Code Playgroud)
使用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;
}
Run Code Online (Sandbox Code Playgroud)
当行
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
Run Code Online (Sandbox Code Playgroud)
被移除,相机应用程序按预期运行.
有没有合理的解决方法?我不想自己制作相机应用程序只是为了拍照.
有问题的线路:
File outputDir = getBaseContext().getCacheDir();
Run Code Online (Sandbox Code Playgroud)
我已将其替换为:
private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "1mind_" + timeStamp + ".jpg";
File photo = new File(Environment.getExternalStorageDirectory(), imageFileName);
return photo;
}
Run Code Online (Sandbox Code Playgroud)
事实证明,图像必须存储在外部存储中,而不是缓存目录中。
| 归档时间: |
|
| 查看次数: |
2762 次 |
| 最近记录: |