Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sensors
public class MainActivity extends AppCompatActivity implements SensorEventListener // class decl
SensorManager manager = (SensorManager) getSystemService(SENSOR_SERVICE); // oncreate
manager.registerListener(this, manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), // oncreate or onresume
SensorManager.SENSOR_DELAY_UI);
manager.unregisterListener(this); // ondestory or onpause
@Override
public void onSensorChanged(SensorEvent event) {
Log.i("UpDown", "values = " + event.values[0] + " " + event.values[1] + " " + event.values[2]);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.