June 2017
Intermediate to advanced
232 pages
5h 4m
English
As described previously, if we want to be notified when the value read by a sensor is changed (or the accuracy is changed) we have to register a listener that extends SensorEventListener. In this project, we want to monitor two different parameters:
Therefore, we need two different listeners, one for each sensor. For the temperature sensor the callback class is shown as follows:
private class TemperatureCallback implements SensorEventListener { @Override public void onSensorChanged(SensorEvent sensorEvent) { float val = sensorEvent.values[0]; Log.d(TAG, "Temp ["+val+"]"); } @Override public void onAccuracyChanged(Sensor sensor, int i) { Log.d(TAG, "T. Accuracy ["+i+"]"); }}
While for ...
Read now
Unlock full access