0

I'm developing an android camera api app that is locked in portrait mode in the manifest file.

android:configChanges="orientation"
android:screenOrientation="portrait"

My problem is, when I store pictures, they are all stored in the same orientation.

I would like them to be stored with the true orientation, eg. my ceiling should be at the top of the stored picture, no matter how I orient my phone, if that makes any sense

In order to do this I have to know the orientation of the device, however it seems that when the app is locked inn portrait, all getOrientation'ish methods thinks my phone is in portrait mode, no matter the physical orientation of my phone.

Here are the ones I've tried:

Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(mCurrentlyUsedCamera,cameraInfo);
Log.e("debug","orientation:"+cameraInfo.orientation);

and

getResources().getConfiguration().orientation

and

this.getWindowManager().getDefaultDisplay().getRotation()

.

Any way of getting the true orientation in a portrait locked app?

.

  • Locking the orientation creates problems, like the one you have experienced. The correct solution would be not to lock the orientation and handle orientation changes in your activities. – Minas Mina Jan 25 '18 at 07:26

1 Answers1

0

In short - you have to use the sensors directly. I kinda got it working, but then I found this guy: Android: get device orientation from Azimuth, roll & pitch

So I basically deleted my all my own code and implemented his utility class :) https://gist.github.com/abdelhady/501f6e48c1f3e32b253a#file-deviceorientation