简体   繁体   中英

Android: get orientation, even if app is locked to portrait

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?

.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM