Skip to content

Instantly share code, notes, and snippets.

Created March 1, 2018 09:50
What would you like to do?
Registering Sensor for the Barometer Tutorial on the SSaurel's Channel
SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
Sensor pressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
SensorEventListener sensorEventListener = new SensorEventListener() {
public void onSensorChanged(SensorEvent sensorEvent) {
float[] values = sensorEvent.values;
txt.setText(String.format("%.3f mbar", values[0]));
public void onAccuracyChanged(Sensor sensor, int i) {
sensorManager.registerListener(sensorEventListener, pressureSensor, SensorManager.SENSOR_DELAY_UI);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment