android 重力感應

鴨脖發表於2012-07-20

sensorMgr = (SensorManager)getSystemService(SENSOR_SERVICE);  

sensor = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

SensorEventListener lsn = new SensorEventListener() {  

public void onSensorChanged(SensorEvent e) {  }

public void onAccuracyChanged(Sensor s, int accuracy) {   
       
        }   

}

sensorMgr.registerListener(lsn, sensor, SensorManager.SENSOR_DELAY_GAME);


在activity finish的時候別忘了unregister


相關文章