Code example for SensorManager

Methods: getDefaultSensorregisterListenerunregisterListener

0
         SensorEvent sSensorEvent;
 
         public generic3AxisSensor(int sensorType) {
             sSensorType = sensorType;
             sSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
             sSensor = sSensorManager.getDefaultSensor(sSensorType);
         } 
 
         public void onAccuracyChanged(Sensor sensor, int accuracy) {
         } 
 
         public void onSensorChanged(SensorEvent event) {
             sSensorEvent = event;
         } 
 
         /** 
          * Enable or disable the Sensor by registering/unregistering 
          */ 
         public void changeStatus(boolean enable) {
             if (enable) {
                 sSensorManager.registerListener(this, sSensor, SensorManager.SENSOR_DELAY_NORMAL);
             } else { 
                 sSensorManager.unregisterListener(this, sSensor);
             } 
         } 
 
         /** 
          * Read the Sensor 
Contextual code suggestions in your IDE  Get Codota for Java