简体   繁体   中英

Android - Camera intent not performing save, as mentioned in documentation

I have a camera intent set up to try to create a file in the root of my device.

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);

When I run my application, I don't have any activityOnResult set, but I use fileExplorer to try to see if my file was created. My folder gets created fine, but the photo does not show up. Any idea why?

The documentation states that if an EXTRA_OUTPUT is set, it will write to that location. So I'm confused why it's not working.

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.

use Uri. try this

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(storagePath));

"..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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM