目前常用的有两种(小三也只有两种)
加速传感器:SENSOR_ACCELEROMETER
姿态传感器:SENSOR_ORIENTATION
经试验
public void onSensorChanged(int sensor, float[] values) {
里的values为如下含义;
当传感器为姿态传感器(SENSOR_ORIENTATION)时values的含义如下:
SENSOR_ORIENTATION , SENSOR_ORIENTATION_RAW :
All values are angles in degrees.
values[0]: Azimuth, rotation around the Z axis (0<=azimuth<360). 0 = North, 90 = East, 180 = South, 270 = West
values[1]: Pitch, rotation around X axis (-180<=pitch<=180), with positive values when the z-axis moves toward the y-axis.
values[2]: Roll, rotation around Y axis (-90<=roll<=90), with positive values when the z-axis moves toward the x-axis.
values[0] 为Yaw轴上的转动角度
values[1] 为Pitch轴上的转动角度
values[2] 为Roll轴上的转动角度
加传感器相应,首先在onCreate里获得系统的sensorsevice
s_sensor = (SensorManager)getSystemService(SENSOR_SERVICE);
之后再Activity类下的onResume里设定监听
然后,在创建监听接口
之后就可以根据获得的s_sensorValue去进行传感器相应啦。
本文介绍了姿态传感器(SENSOR_ORIENTATION)的基本原理及其在Android平台的应用。详细解释了传感器返回的三个角度值(Yaw、Pitch 和 Roll)的意义,并给出了具体的实现代码。
2152

被折叠的 条评论
为什么被折叠?



