Search code examples
androidscreen-orientationandroid-4.2-jelly-beancameracapturetask

How can we lock the camera screen orientation during the camera capture process?


Our camera takepicture takes around 10-15 seconds (due to custom camera hardware). What I need is during this process of 10-15 seconds, I would not want the user to change the screen orientation.

I have placed the takepicture call in doInBackground of Async task.

In the onPreExecute() method I have placed

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

And in onPostExecute I placed

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

This solution doesn't work for me and causes the camera and device to be crashed and I had to reboot the device.


Solution

  • Did you try blocking the orientation from the AndroidManifest ? by adding the below line in your camera activity

    <activity android:label="@string/activity_name" android:screenOrientation="portrait" />
    

    or

    <activity android:label="@string/activity_name" android:screenOrientation="landscape" />