其中传感器应被用来确定是否装置已经通过使用Android传感器倾斜向上或向下 [英] Which sensor should be used to determine whether device has been tilted UP or Down by using Android Sensor
问题描述
哪个传感器应当用于确定设备是否已使用Android的传感器倾斜向上或向下?在此输入code
Which sensor should be used to determine whether device has been tilted UP or Down by using Android Sensor ?enter code here
通过下面的code:
SensorManager.getRotationMatrix(mRotationMatrix, null, mValuesAccel,mValuesMagnet);
SensorManager.remapCoordinateSystem(mRotationMatrix,
SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, R2);
SensorManager.getOrientation(R2, mValuesOrientation);
enter code here
我米获得三个方向值(方位角,俯仰,滚动)
我该如何使用三个方向值,以确定是否设备已经向上或向下倾斜。
I m getting three orientation values(azimuth,pitch,roll) How can i use three orientation values to determine whether device has been tilted up or down.
推荐答案
要获得设备倾斜,以及其它的攻击角度,你需要注册一个监听器TYPE_ACCELEROMETER和TYPE_MAGNETIC_FIELD事件:
To get the device tilt, as well as other attack angles you will need to register a listener for TYPE_ACCELEROMETER and TYPE_MAGNETIC_FIELD events:
mngr = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
accelerometer = mngr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magneticField = mngr.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
int rate = SensorManager.SENSOR_DELAY_GAME; // or other
mngr.registerListener(sensorListener, accelerometer, rate);
mngr.registerListener(sensorListener, magneticField, rate);
在监听器被激活,您将需要调用
Once listener is activated, you will need to call
SensorManager.getOrientation()
获取方位角(Z),音调(X)及电流值;卷(Y)。
to obtain current values for azimuth(z), pitch(x) & roll(y).
您可以在这里找到详细的code例如:<一href=\"http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple.html\">http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple.html
You can find a detailed code example here: http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple.html
这篇关于其中传感器应被用来确定是否装置已经通过使用Android传感器倾斜向上或向下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!