How to rotate camera in Android?

Asked by At

In my Manifest, I've set my activity mode to the Landscape mode:

<activity android:name=".TakePictureActivity" android:screenOrientation="landscape" android:theme="@style/Theme.AppCompat.NoActionBar"></activity>

And in my activity class I use camera like:

private fun openCamera() {
    val values = ContentValues()
    values.put(MediaStore.Images.Media.TITLE, "New Picture")
    values.put(MediaStore.Images.Media.DESCRIPTION, "From the camera")
    image_uri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)

    val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, image_uri)
    startActivityForResult(cameraIntent, IMAGE_CAPTURE_CODE)
}

but I do not know why, while my activity screen is in landscape mode, the camera is still in portrait mode. After taking a photo, in the preview screen of the camera, not my own activity, the photo is shown in portrait mode. Is there a way by which I can rotate my camera and get the final photo in landscape mode? I am completely new in Android, so I hope I do everything right Thanks in advance!

0 Answers