Android 开发中重力感应的实例 sample code
2010-03-11 15:50:00 来源:WEB开发网核心提示:SensorEventListener lsn = new SensorEventListener() {public void onSensorChanged(SensorEvent e) {x = e.values[SensorManager.DATA_X];y = e.values[SensorManager.D
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);
}
}
更多精彩
赞助商链接