2

I've googled a lot and found a few threads on stack overflow but it didnt help out. Im trying to use the built-in camera of Android by invoking an Intent. This works on 2.1 but on 2.2 i get the "FATAL EXCEPTION: GLThread 11" exception.

I read this topic Camera crashes in Android 2.2

And the google thread http://code.google.com/p/android/issues/detail?id=7909

    String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "temp-" + System.currentTimeMillis() + ".jpg";

    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, fileName);
    values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");

    imageUri = ctx.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);


    //http://marakana.com/forums/android/examples/39.html
    ctx.startActivityForResult(intent, REQUEST_CODE);

This is the code that i use to invoke the camera. Straightforward i guess. But when i take the picture and hit the 'save'/'accept' button the app crashes in Android 2.2. In my opinion it's standard code and functionality. How can i use the built-in camera. I've tried several things.

1 Answer 1

2

Let me answer it myself:) I managed to get it working. Im still discovering Android. First of all the code above will never work. Nonetheless its still a hell of a job to work with camera ... and test it. I cant get the intent working in the emulator for 2.2, for 2.1 it works. But the code works for 2.2 and 2.1 on the device. Another weird thing that i discovered is that when you attach the debugger to your device its not possible to use MediaStore.Images.Media.EXTERNAL_CONTENT_URI. It throws an error that the external storage doesnt exist. It has to do with the USB connection. Anyway, the code used to intent the camera:

        String fileName = System.currentTimeMillis() + ".jpg";
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, fileName);
        values.put(MediaStore.Images.Media.DESCRIPTION, "Image capture by camera");
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");

        try
        {
            imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        }
        catch (Exception e)
        {
            Log.e(TAG, "", e);
        }

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);

        ctx.startActivityForResult(intent, REQUEST_CODE_PHOTO);

Pretty standard, i added the try catch to avoid that the app crashed when i attach a debugger to my device. If you pass null for MediaStore.EXTRA_OUTPUT the camera will show a message that the sdcard could not be found. Which is better then crashing.

After you take the picture the camera will return to your current activity and you can use the image which will be stored in the imageUri variable.

In the emulator for 2.2 the error “FATAL EXCEPTION: GLThread 11” is still thrown when i try to use the camera, which is annoying. Does anyone has a solution to get it working on the emulator?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.