简体   繁体   English

Android光传感器不会触发事件

[英]Android light sensor not triggering event

When using the light sensor, I have an issue where the onSensorChanged() event is never triggered. 使用光传感器时,我遇到一个问题,即从不触发onSensorChanged()事件。 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! 恒定勒克斯值0和常数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? 那么如果lux值是常数,如何获得lux值,从而永远不会触发事件? Is there a way to set a false value initially (such as -1) so an event will always occur? 有没有办法最初设置一个假值(如-1),所以总会发生一个事件? Or am I thinking about this wrong? 或者我在考虑这个错误?

Any assistance would be greatly appreciated! 任何帮助将不胜感激!

Check following example, It explained how to use Sensors 检查以下示例,它解释了如何使用传感器

Android Light Sensor Android光传感器

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. 啊好吧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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