Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using phone camera via Intent - activity never returns?

I'm using the phone's camera in an Android app to take a photo. I'm using Intents to use the built-in camera application and I'm using the following code:

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(FILEPATH)));
startActivityForResult(intent, ACTIVITY_NATIVE_CAMERA_AQUIRE);

It works fine and the camera is brought up. I can take a photo and the phone presents me with three options: Cancel, Retake, OK. The first two work, pressing cancel returns the user to the app, but pressing OK and nothing happens. Apparently onActivityResult isn't being called, and the camera just stays on the screen. Nothing in the debugger either.

Running the app on a Nexus One with Android 2.2.1. Same problem on the emulator running Android 2.0.

Edit: Tested on a HTC Desire running Android 2.2 with HTC's Sense UI: works perfectly. Nothing on the emalator nor Google N1.

Edit2: It seems that the HTC Desire image aquiring activity works better in the sense that it does return, but it disregards the EXTRA_OUTPUT -setting and returns only a small image in the onActivityResult -call. Checking on the ddms console while the phone is hooked to the computer I see that the phone is storing the image on the SD card, but the path is not passed back to my application. It is starting to look like there is no reliable way to use the camera intent, and get back a reasonably-sized image. Bad, bad, bad.

like image 314
TuomasR Avatar asked Nov 14 '22 06:11

TuomasR


1 Answers

After a bit of research, testing and sheer luck I managed to solve this issue.

If the EXTRA_OUTPUT -option for the Intent contains a file URI that points to the internal memory of the device, the call will fail. How it fails, depends on the device. The HTC Desire works ok on the surface, but fails to return the full-sized image. Google N1 on the other hand refuses to leave from the camera activity.

When I changed the file URI to point to the memory card, it worked perfectly for both the Desire and Google N1.

So summing it up: the path to store the full sized image MUST point to the SD card.

like image 113
TuomasR Avatar answered Nov 17 '22 05:11

TuomasR