1 Answer
1

As noted here, it isn't possible to directly get the current sensor value and, while some more recent versions of Android will generate an onSensorChanged event as soon as the listener is registered (allowing you to get a baseline), earlier versions don't. So the only thing you can really do is hope that the user is either running a more recent version of Android or that the value changes and then retrieve the current lux value from event.values[0] inside onSensorChanged (e.g.) :

(After changing maxLux and currentLux to floats). This then leaves the issue of retrieving the current value based on a button press, which can be done by looking at the value of currentLux at the time the button is pressed.

Thanks for the help! I don't need a constant value only when it changes. I made a few adjustments to your code. maxLux will be a constant based on the original calibration (what the button press is for) then the brightness of the screen will change based on a percentage of currentLux from maxLux
–
CistoranJun 22 '11 at 5:45