Getting lux value from light sensor without onSensorChanged () event?

Just wondering if there is a way to get the light sensor value on an Android phone without waiting for the onSensorChanged () event? To save battery, I use registerListener () and unregisterListener () after getting one lux value, however the next time I register the listener to get a different value, if this value is the same as before, my application sits there, waiting an event that may take some time (usually in low light situations).

So, is there a way I can read the lux value without waiting for the onSensorChanged () event? Or should I just have a timeout of 100 ms and then use the last value that I wrote down?

Thanks!

+6
source share
1 answer

I also wanted to achieve the same value for accelerometer or compass , i.e. to get the current value only without listening to the change events and wait until any physical change occurs, but after a lot of searching, I came to the conclusion that this is impossible.

The only way to read values ​​from these devices is to listen to events continuously.

+5
source

Source: https://habr.com/ru/post/888687/


All Articles