1
我想獲得我的DEVICE的實際方向。我不想要這樣的版面排版:Android get設備方向
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
return display.getOrientation();
我想獲得物理設備方向。有沒有什麼辦法讓它在android中?
我想獲得我的DEVICE的實際方向。我不想要這樣的版面排版:Android get設備方向
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
return display.getOrientation();
我想獲得物理設備方向。有沒有什麼辦法讓它在android中?
使用方向變化監聽
OrientationEventListener mOrientatinChangeListener = new OrientationEventListener(getApplicationContext(), SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
// Here you will get the actual orientation
}
};
protected void onStart() {
super.onStart();
// Activate the Orientation change listener
mOrientatinChangeListener.enable();
}
注:如果您是從陀螺儀期待一個3維方向/ accellerometer然後Using Android gyroscope instead of accelerometer. I find lots of bits and pieces, but no complete code
http://stackoverflow.com/questions/10380989/how-do- i-get-the-current-orientation-activityinfo-screen-orientation-of-an-a –
在此答案中試用此方法[http://stackoverflow.com/questions/22456024/how-to-get-the-android -devices-physical-orientation-in-度] [1] [1]:http://stackoverflow.com/questions/22456024/how-to-get-the-android-devices-physical-orientation-in-degrees – QArea