Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

like image 876
user1917105 Avatar asked Dec 19 '12 22:12

user1917105


People also ask

What is the maximum value of the light sensor?

getMaximumRange() returns value above 10000, while light sensor event gives value 0 when it's dark and value 5 when it's pretty much sunny outside.

What is the range of a light sensor?

The Light Sensor is an analog sensor, and it returns values in the range of 0 to 4095. Higher values indicate that the sensor is in a darker area, and lower values indicate lighter areas. Note: Remember that it is important to calibrate your Light Sensor by calculating a threshold value.

How sensors work in Android?

These sensors measure acceleration forces and rotational forces along three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors. These sensors measure various environmental parameters, such as ambient air temperature and pressure, illumination, and humidity.


1 Answers

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

like image 128
DoogyHtw Avatar answered Sep 18 '22 01:09

DoogyHtw