는 다음과 같이 당신의 SensorFusionActivity에 mDisplay 변수를 추가 : 마지막으로
mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
을 calculateAccMagOrientation 이런 식으로 수정 :
private Display mDisplay = null;
를 다음에서 onCreate 방법에 다음 코드를 추가
을
// calculates orientation angles from accelerometer and magnetometer output
public void calculateAccMagOrientation() {
if(SensorManager.getRotationMatrix(rotationMatrix, null, accel, magnet)) {
int rotation = mDisplay.getRotation();
if(rotation == Surface.ROTATION_0)
SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, rotationMatrix);
else if(rotation == Surface.ROTATION_180)
SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, rotationMatrix);
else if(rotation == Surface.ROTATION_270)
SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_MINUS_X, SensorManager.AXIS_MINUS_Y, rotationMatrix);
SensorManager.getOrientation(rotationMatrix, accMagOrientation);
}
}
당신이 읽어 그래서이 질문은? http://stackoverflow.com/questions/10192057/android-getorientation-method-returns-bad-results –