For my app I need to get the maximum value of light sensor. I thought it was the same for all devices which have light sensor (ie SensorManager.LIGHT_SUNLIGHT_MAX) but according to sample tests made on devices I was wrong.
The problem is that with SensorListener you can only know when the value has changed.
So my question is: How to get maximum value of light sensor (assuming that the user can put a powerfull light in front of the sensor that, ie light value > maximum sensor value) ?
A solution could be looking at value growth but I don't know how to manage it.
getMaximumRange() returns value above 10000, while light sensor event gives value 0 when it's dark and value 5 when it's pretty much sunny outside.
The Light Sensor is an analog sensor, and it returns values in the range of 0 to 4095. Higher values indicate that the sensor is in a darker area, and lower values indicate lighter areas. Note: Remember that it is important to calibrate your Light Sensor by calculating a threshold value.
These sensors measure acceleration forces and rotational forces along three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors. These sensors measure various environmental parameters, such as ambient air temperature and pressure, illumination, and humidity.
Use following method :
getMaximumRange()
Implementation :
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Sensor lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
maxvalue = lightSensor.getMaximumRange();
Source :
http://developer.android.com/reference/android/hardware/Sensor.html#getMaximumRange()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With