所以...我似乎有HTC的这个问题,运行cyanogenmod。上面的 答案似乎不回答这个问题,但也许我只是想念它。
我解决了orientationEventListener,同时也使用onresume和Display.getRotation()跟踪方向(我用它来设置exif旋转数据在图像文件中)。
中的onResume
我做的:
if (display.getRotation() == Surface.ROTATION_0){ // portrait
mPicOrientation = ExifInterface.ORIENTATION_ROTATE_90;
}else if (display.getRotation() == Surface.ROTATION_270){ // CW 90
mPicOrientation = ExifInterface.ORIENTATION_ROTATE_180;
}else if (display.getRotation() == Surface.ROTATION_180){ // portrait inverted
mPicOrientation = ExifInterface.ORIENTATION_ROTATE_270;
}else{ // CW 270
mPicOrientation = ExifInterface.ORIENTATION_ROTATE_270;
}
中的onCreate我安装
实现onOrientationChange的orientationEventListener:
OrientationEventListener mOrientationEventListener = new OrientationEventListener(
context, SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
if (orientation >= 315 && orientation < 45) { // portrait upright
mPicOrientation = ExifInterface.ORIENTATION_ROTATE_90;
} else if (orientation >= 45 && orientation < 135) { // CW 90
mPicOrientation = ExifInterface.ORIENTATION_ROTATE_180;
} else if (orientation >= 135 && orientation < 225) { // portrait upside down
// FIXME: this one is also 270?? display.getrotation is broken at least...
mPicOrientation = ExifInterface.ORIENTATION_ROTATE_270;
} else if (orientation >= 225 && orientation < 315) {
mPicOrientation = ExifInterface.ORIENTATION_ROTATE_270;
}
//Log.d(picGlobals.TAG, "orientation: " + orientation + " surface_rotation: " + mPicOrientation);
}
};
if (mOrientationEventListener.canDetectOrientation()) {
mOrientationEventListener.enable();
}
的图片所产生的最终旋转是无意义的画像与反转朝向。我不知道为什么。它可能是我测试的少数设备。
我会再次在模拟器中测试,但真的很难分辨它的模拟相机图片是否颠倒(感谢谷歌)。 它的工作原理大多数的时候纵向倒置。但不是所有的时间。无论如何,我真的想要这样拍照吗? orientationEventListener每次都有效。但是直到你真正改变方位(当然不知道门槛是什么),它才会被触发。这就是为什么我在onResume中有Display.getRotation()。
因此,当我做180翻转时,似乎onCreate()或甚至onResume()不会被执行。所以也许这不是应用程序检测旋转的正确方法。任何人都知道我是否可以使用某种“onRotate”侦听器? – 2011-04-27 14:23:58
嗨,安迪jay.I我面临同样的问题,当我快速打开设备.plz告诉我如何检测突然180度turn.thanks – Amrendra 2013-04-25 06:24:30
我从来没有能够找出一种方法来检测。对不起,哥们。 :( – 2013-04-26 20:52:47