简体   繁体   English

Android:获取光传感器的最大值

[英]Android : Get the maximum value of light sensor

For my app I need to get the maximum value of light sensor. 对于我的应用程序,我需要获得光传感器的最大值。 I thought it was the same for all devices which have light sensor (ie SensorManager.LIGHT_SUNLIGHT_MAX) but according to sample tests made on devices I was wrong. 我认为所有具有光传感器的设备(即SensorManager.LIGHT_SUNLIGHT_MAX)都是一样的,但根据设备上的样本测试我错了。

The problem is that with SensorListener you can only know when the value has changed. 问题是,使用SensorListener,您只能知道值何时发生了变化。

So my question is: How to get maximum value of light sensor (assuming that the user can put a powerfull light in front of the sensor that, ie light value > maximum sensor value) ? 所以我的问题是:如何获得光传感器的最大值(假设用户可以在传感器前放置一个强光,即光值>最大传感器值)?

A solution could be looking at value growth but I don't know how to manage it. 解决方案可能是关注价值增长,但我不知道如何管理它。

Use following method : 使用以下方法:

getMaximumRange()

Implementation : 实施:

SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Sensor lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
maxvalue = lightSensor.getMaximumRange(); 

Source : 资源 :

http://developer.android.com/reference/android/hardware/Sensor.html#getMaximumRange () http://developer.android.com/reference/android/hardware/Sensor.html#getMaximumRange ()

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

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