简体   繁体   中英

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

Just wondering, is there a way to gain the value of the light sensor on an Android phone without waiting for an onSensorChanged() event to occur? To save battery I use registerListener() and unregisterListener() after getting a single lux value, however the next time I register the listener to get another value, if that value is the same as before, my application sits there waiting for an event which may take a while to occur (typically in low-light situations).

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

Thanks!

I also wanted to achieve the same for accelerometer or compass ie get the current value only without listening on to the change events and wait for any physical change to occur but after lot of search I have came to conclusion that it is not possible.

Only way to read value from these devices is to listen for events continuously.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM