June 2017
Intermediate to advanced
232 pages
5h 4m
English
Once we have implemented the custom callback classes, we have to register them in order to receive the events. We can do it only when the Android Things app is notified that the sensor is connected otherwise we cannot register the listeners. In this step, the app uses SensorManager.DynamicSensorCallback to handle this notification event.
In MainActivity.java add the following lines:
private class BMX280Callback extends SensorManager.DynamicSensorCallback { @Override public void onDynamicSensorConnected(Sensor sensor) { int sensorType = sensor.getType(); Log.d(TAG, "On Sensor connected..."); if (sensorType == Sensor.TYPE_AMBIENT_TEMPERATURE) { Log.d(TAG, "Temp sensor.."); tempCallback= new TemperatureCallback(); ...Read now
Unlock full access