Android : Get the maximum value of light sensor

女生的网名这么多〃 提交于 2020-01-01 12:35:08

问题


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.

The problem is that with SensorListener you can only know when the value has changed.

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.


回答1:


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()



来源:https://stackoverflow.com/questions/13962023/android-get-the-maximum-value-of-light-sensor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!