April 2016
Intermediate to advanced
194 pages
4h 37m
English
In this section, we will get the ambient temperature from the phone temperature sensor and will show it in the foreground activity. Before accessing the value for ambient temperature, we will also check the availability of the temperature sensor on the device.
TemperatureActivity and implemented it with the SensorEventListener interface so that it receives the ambient temperature values. We are also checking if the ambient temperature is available on the device and are maintaining the availability state using the isSensorPresent Boolean variable. If the temperature sensor is not present, then we show the relevant message using TextView. The following code snippet shows the necessary steps: ...