We are trying to use the native camera app to let the user take a new picture. It works just fine if we leave out the EXTRA_OUTPUT extra
and returns the small Bitmap image. However, if we putExtra(EXTRA_OUTPUT,...)
on the intent before starting it, everything works until you try to hit the "Ok" button in the camera app. The "Ok" button just does nothing. The camera app stays open and nothing locks up. We can cancel out of it, but the file never gets written. What exactly do we have to do to get ACTION_IMAGE_CAPTURE
to write the picture taken to a file?
Edit: This is done via the MediaStore.ACTION_IMAGE_CAPTURE
intent, just to be clear
I created simple library which will manage choosing images from different sources (Gallery, Camera), maybe save it to some location (SD-Card or internal memory) and return the image back so please free to use it and improve it - Android-ImageChooser.
To follow up on Yenchi's comment above, the OK button will also do nothing if the camera app can't write to the directory in question.
That means that you can't create the file in a place that's only writeable by your application (for instance, something under
getCacheDir())
Something undergetExternalFilesDir()
ought to work, however.It would be nice if the camera app printed an error message to the logs if it could not write to the specified
EXTRA_OUTPUT
path, but I didn't find one.I recommend you to follow the android trainning post for capturing a photo. They show in an example how to take small and big pictures. You can also download the source code from here
It is very simple to solve this problem with Activity Result Code Simple try this method
I had the same problem where the OK button in camera app did nothing, both on emulator and on nexus one.
The problem went away after specifying a safe filename that is without white spaces, without special characters, in
MediaStore.EXTRA_OUTPUT
Also, if you are specifying a file that resides in a directory that has not yet been created, you have to create it first. Camera app doesn't do mkdir for you.I've been through a number of photo capture strategies, and there always seems to be a case, a platform or certain devices, where some or all of the above strategies will fail in unexpected ways. I was able to find a strategy that uses the URI generation code below which seems to work in most if not all cases.
To contribute further to the discussion and help out newcomers I've created a sample/test app that shows several different strategies for photo capture implementation. Contributions of other implementations are definitely encouraged to add to the discussion.
https://github.com/deepwinter/AndroidCameraTester