Search code examples
androidcameraorientationaccelerometersensors

How to start camera intent without accelerometer sensor?


I'm currently writing a application that needs to capture some images. I start the camera application using a intent like this:

if (v.equals(btnCap)) {
        Intent cameraIntent = new Intent(
                android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
        startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
    }

The problem is: When i tilt my device, the buttons on the camera still change their orientation and the picture I receive is not in portrait.

Does anyone know how to capture a image in portrait mode, even if the device is tilted?

Thanks in advance, Adrian


Solution

  • You best option is to create your own camera app (http://developer.android.com/guide/topics/media/camera.html#custom-camera).

    And then, in your AndroidManifest.xml, add the android:screenOrientation="portrait" option on the declaration of your activity.

    It's better to build your own camera activity, because you can have issues for getting the pictures depending on the device model. I once had an issue with Samsung devices (see Android Samsung: Camera app won't return intent.getData())