I am trying to use Sensor.Type_Light or the Light Sensor to detect change in event.values[0].
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType()== Sensor.TYPE_LIGHT) {
debugView = (TextView)findViewById(R.id.lightValue);
debugView.setText("Detecting...." +event.values[0]);
}
As you can see, The values are displayed in a TextView. Also, we know that if event.values[0] is 0, there is no light and as the light increases, the value also increases. Now my question is: How can I use this event.values[0] to detect significant change in light that is, if I activate my Sensor in adequate light (event.values[0] >15), it should be able to trigger an event when light turns off (event.values[0] < 3) and vice-versa.
Thanks in advance
I tried the following in onSensorChanged, but nothing seems to work.
if(event.values[0] >= 0 && event.values[0] <5) {
// No Light
if(event.values[0] > 10) {
callForHelp();
}
}
else {
if(event.values[0] > 15) {
// Light On
if(event.values[0] < 5) {
callForHelp();
}
}
}
Inside onSensorChanged(), why don't you do exactly what you say you want: