Search code examples
androidcameraandroid-camerauser-experience

Force User to Capture Image in Landscape mode


I would like my app to force a user to turn their phone sideways to take an image. In other words, I would like the image to be taken in landscape mode. How do I go about this?

At the very least, the image will be taken and saved in landscape even if user does not tilt their phone to the side.


Solution

  • You can simply add this line in your onCreate() method inside your activity

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    

    or if you need portrait write this

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);