且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的光传感器不触发事件

更新时间:2023-11-19 12:26:04

我是pretty的肯定是没有办法解决这个问题。你只需要希望,在设定的时间量勒克斯的变化,之前直接询问用户。稀释好。

When using the light sensor, I have an issue where the onSensorChanged() event is never triggered. The reason is that when the listener is registered, if the lux value remains constant, there's no change thus no event. However, I still want to know the lux value! There's a difference between a constant lux value of 0, and a constant of 60,000!

After some research, I realised that there's no way to directly read the lux value of the sensor. So how do I get the lux value if it's constant, and thus will never trigger an event? Is there a way to set a false value initially (such as -1) so an event will always occur? Or am I thinking about this wrong?

Any assistance would be greatly appreciated!

I'm pretty sure there is no solution to this problem. You just need to hope that the lux changes within a set amount of time, before asking the user directly. Ahh well.