简体   繁体   English

如何使用光传感器

[英]how to use the light sensor

I want to use light sensor to detect the environment of phone changing, then protect the phone from being stolen. 我想使用光传感器检测手机更换的环境,然后防止手机被盗。 But I don't know whether, if the screen is turned off, the sensor still works or not. 但是我不知道如果屏幕关闭,传感器是否仍然可以工作。 And, can anybody make some suggestions how can I make this goal? 而且,有人可以提出一些建议,如何实现这一目标? If I register a sensor in the service, will i make it? 如果我在服务中注册了传感器,我会成功吗?

I know that, using context.getSystemService(SENSOR_SERVICE), I can get the sensormanager, register the sensor, and implement the SensorEventListener. 我知道,使用context.getSystemService(SENSOR_SERVICE),我可以获取sensormanager,注册传感器并实现SensorEventListener。 Through the sensorevent.value I can get the value of lightsensor. 通过sensorevent.value,我可以获得光传感器的值。

Yes you can actually use the sensor API here. 是的,您实际上可以在此处使用传感器API。 Even if the screen is not active, the sensor will still work. 即使屏幕未激活,传感器仍然可以工作。 But be careful, so as not to have it go on for a long time. 但是要小心,以免长时间持续。 As this will drain enormous battery power and reduce battery longevity . 因为这将消耗大量电池电量并降低电池寿命。

"Always make sure to disable sensors you don't need, especially when your activity is paused. Failing to do so can drain the battery in just a few hours. Note that the system will not disable sensors automatically when the screen turns off." “始终确保禁用不需要的传感器,尤其是在您的活动暂停时。不这样做可能会在短短几个小时内耗尽电池。请注意,当屏幕关闭时,系统不会自动禁用传感器。”

"To optimize our app for performance, it is the best practice to get the notifications just while your app is in running state." “为了优化我们的应用程序的性能,最好的方法是在您的应用程序处于运行状态时获取通知。”

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

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