0

我设置了一个相机意图来尝试在我的设备的根目录中创建一个文件。

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设置了 an ,它将写入该位置。所以我很困惑为什么它不起作用。

调用者可能会传递一个额外的 EXTRA_OUTPUT 来控制该图像将被写入的位置。如果 EXTRA_OUTPUT 不存在,则在额外字段中将小尺寸图像作为位图对象返回。这对于只需要小图像的应用程序很有用。如果存在 EXTRA_OUTPUT,则将全尺寸图像写入 EXTRA_OUTPUT 的 Uri 值。

4

2 回答 2

3

使用乌里。尝试这个

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(storagePath));
于 2013-07-25T01:10:00.793 回答
1

"..will be written to the Uri value of EXTRA_OUTPUT."

You are passing in a File object (storagePath). It expects a Uri so use this:

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(storagePath));
于 2013-07-25T01:07:42.013 回答