Registering Sensor for the Barometer Tutorial on the SSaurel's Channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); | |
Sensor pressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); | |
SensorEventListener sensorEventListener = new SensorEventListener() { | |
@Override | |
public void onSensorChanged(SensorEvent sensorEvent) { | |
float[] values = sensorEvent.values; | |
txt.setText(String.format("%.3f mbar", values[0])); | |
} | |
@Override | |
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