0
我知道有關於此的線程,我一直在閱讀它們好幾天。安卓傳感器直立旋轉
我覺得我的問題更具體。我試圖讓設備旋轉y軸。
如果我正確的,它被稱爲方位角
當運行應用程序,它經過調試記錄值[0],值在logcat的返回0.0 [1],&值[2]
代碼:
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
SensorEventListener SEL = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
mSensorManager.getRotationMatrix(rotationMatrix, I, gravity, geomagnetic);
mSensorManager.getOrientation(rotationMatrix, values);
accy = values[0];
System.out.println(accy);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
int rate = SensorManager.SENSOR_DELAY_GAME;
mSensorManager.registerListener(SEL, accelerometer, rate);
mSensorManager.registerListener(SEL, magnetometer, rate);
logcat的:
09-05 17:34:02.622 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.642 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.642 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.662 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.662 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.682 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.682 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.702 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.702 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.722 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.722 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.742 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.742 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.762 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.762 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.782 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.782 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.802 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.802 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
確定。現在,這似乎很明顯。我想我沒有完全理解功能如此惡劣做一些研究。謝謝。 – ahew 2014-09-06 02:35:45
看看http://stackoverflow.com/questions/17979238/android-getorientation-azimuth-gets-polluted-when-phone-is-tilted/17981374#17981374 – 2014-09-06 02:55:12
完美。這就是我一直在尋找的東西。 – ahew 2014-09-06 14:33:26