Android重力感应实现方法
2010-05-19 16:14:00 来源:WEB开发网核心提示:sensorMgr = (SensorManager)getSystemService(SENSOR_SERVICE);SensorEventListener lsn = new SensorEventListener() {public void onSensorChanged(SensorEvent e) {x =
sensorMgr = (SensorManager)
getSystemService(SENSOR_SERVICE);
SensorEventListener lsn = new SensorEventListener() {
public void onSensorChanged(SensorEvent e) {
x = e.values[SensorManager.DATA_X];
y = e.values[SensorManager.DATA_Y];
z = e.values[SensorManager.DATA_Z];
setTitle("x="+(int)x+","+"y="+(int)y+","+"z="+(int)z);
}
public void onAccuracyChanged(Sensor s, int accuracy) {
}
};
//注册listener,第三个参数是检测的精确度
sensorMgr.registerListener(lsn, sensor,
SensorManager.SENSOR_DELAY_GAME);
}
}
以上即Android重力感应的相关实现方法。
更多精彩
赞助商链接