我设置了相机 Intent ,尝试在设备的根目录中创建文件。
File storagePath = new File(Environment.getExternalStorageDirectory()+ "/Football_Fans");
storagePath.mkdirs();
File file = new File(storagePath, "FAN_IMAGE_TEMP");
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, storagePath);
startActivityForResult(cameraIntent,CAMERA_REQUEST_IMAGE);
当我运行我的应用程序时,我没有设置任何 ActivityOnResult,但我使用 fileExplorer 来尝试查看我的文件是否已创建。我的文件夹创建得很好,但照片没有显示。知道为什么吗?
文档指出,如果设置了 EXTRA_OUTPUT
,它将写入该位置。所以我很困惑为什么它不起作用。
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.
最佳答案
使用 Uri。试试这个
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(storagePath));
关于java - Android - 相机 Intent 不执行保存,如文档中所述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17847243/