5

I'm having problems with a Galaxy Tab Limited Edition ( Google I/O ) when I open the camera whit an Intent.

This is my code:

Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new     
    File(mSavedFilePath)));
startActivityForResult(imageCaptureIntent, REQUEST_IMAGE_CAPTURE);

On a Motorola Xoom this code is working fine. But on Galaxy Tab 10.1, never I receive the response from the camera app.

I haven't a stack trace because i haven't an error.

Anyone have any idea?

Macarse
  • 91,829
  • 44
  • 175
  • 230
PipiBadenas
  • 245
  • 1
  • 3
  • 10
  • You couldn't get any information from logcat? – Macarse Jun 14 '11 at 12:51
  • Have you updated your device to 3.1 yet? Much of the internal apps had bugs on the 3.0 release that came on that device. You might try manually updating to 3.1 and trying again. – devunwired Jun 14 '11 at 12:53

4 Answers4

3

You don't need the camera permission when launching an intent to the camera app. However this is a highly fragmented process on the android platform. i have had a lot of issues with it. basically if you check the extra file that you sent to the camera app you will notice that his size is 0 bytes when the result returns. this bug exists in a lot of android devices and thee is a workaround to fixing most of it and that is when this fails (this means there is no parceable extra output returned and if it is then the extra file is not created or with lenght 0 then you need to get the Uri from the intent like: intent.getData(); this will return an uri to the file which is basically formed the same way as the Extra Output Uri so you can afterwards use the same approach for obtaining the image.

You will notice the image is stored within the Media.Images provider and in the camera directory and ofc the intent.getData() Uri pointing in there.

Hope this helps. Don't forget to vote :D.

DArkO
  • 15,880
  • 12
  • 60
  • 88
  • Thanks for your response. I can't get the data from Intent because the camera doesn't return the control to my app. The onActivityResult() is never called after taking a photo. – PipiBadenas Jun 14 '11 at 14:05
  • do you start the camera app with startActivityForResult(intent)?? oh as i see you are... but it should return at least some kind of result... when you return to an activity that called another one for result you always get a result :D. thats the rule.. it might be Activity.Cancel or Activity.Ok or some other third party code... – DArkO Jun 14 '11 at 14:26
  • But there is still the chance that the camera app doesn't work in a standard way. As far as i have seen so far there isn't a defined intent/way from android to actually get results from a camera intent. it all depends on the manufacturers implementation. even though they strive to make it possible they fail most of the times and that is the ugly truth, especially in beta versions and early releases. – DArkO Jun 14 '11 at 14:56
  • 2
    Uri u = data.getData(); on Samsung phones will provide NullPointerException. – Oh Danny Boy Sep 30 '11 at 19:44
2

I was very frustrated by this as well. However, I did find a (rather pitiful) workaround.

I should say, right off, that I was not using the standard ACTION_IMAGE_CAPTURE Intent. Because I wanted to have the camera image in a window, I used my own layout and I used the following as a template:

How to Program the Google Android Camera to Take Pictures

Tapping the screen calls the Camera.PictureCallback function onPictureTaken(byte[] imageData, Camera c), which is where I grab the byte[] containing the picture. I have a global variable "byte[] MainApplication.snapshotBytes" that is assigned by the imageData from this function.

Now that the data has been saved globally, and is available to the calling Activity, how should the current activity be terminated such that the calling activity is notified? Well, there are a number of ways, but I realized early on that pressing the back button still calls OnActivityResult(...). So, I did the following:

   if (imageData != null)
   {    
      MainApp.snapshotBytes = imageData;

      setResult(RESULT_OK);
      onBackPressed();
   }

The calling Activity was now responsible for three more things.

1: It sets the MainApp.snapshotBytes = null before starting the camera Activity.

2: When the OnActivityResult(...) was called, it first checked the *resultCode == RESULT_OK*, and then made use of the image data that was stored in the global MainApp.snapshotBytes.

3: Finally, it set the MainApp.snapshotBytes = null again so that the memory could be reclaimed by GC.

I'll be the first one to admit that it's a kludge, but it works and is compatible with or without the Camera-null-Intent bug.

I hope this helps!

0

It sounds like a Bug...

But just in case, Have you included on your AndroidManifest.xml the following ???

    <uses-permission android:name="android.permission.CAMERA"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

Also you can try to use the Intent without extras.

    Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(imageCaptureIntent, REQUEST_IMAGE_CAPTURE);

The resulting bitmap will be smaller but at least you can try it to see if it works. I hope it helps.

Regards,

0

Sounds like it could be related to this http://kevinpotgieter.wordpress.com/2011/03/30/null-intent-passed-back-on-samsung-galaxy-tab/

There is another open question which may give additional information

Community
  • 1
  • 1
Moog
  • 10,193
  • 2
  • 40
  • 66