Time for action – adjusting the screen brightness using the light sensor
One of the most common use cases for the light sensor is to adjust the screen brightness according to the external lighting conditions. The maximum range of the light sensor might be different on different Android devices, but most of them support from 0 lux to several thousand lux. Lux is the standard unit for measuring the luminance of the light falling on a surface. For our example, we will use a range from 0 to 100 lux, as normal indoor lighting falls within this range. But for sunlight and strong lights the range can go up to 1,000 lux or more. In the sample app, we will increase the screen brightness, when the indoor lighting goes low, and similarly we will decrease the screen brightness when it goes high.
We followed the standard steps to get values from the sensor. We select the sensor type to the
TYPE_LIGHT
in thegetDefaultSensor()
method ofSensorManager
. We also called the custominitScreenBrightness()
method...