I am new to using sensors in Android and a little confused. I need to perform some actions only with a significant change in light, for example. the light turned on in a dark room. So far, I have a pretty simple default implementation. How can I tell the system that I only want to respond to a significant change in light?
public class MainActivity extends Activity implements SensorEventListener { private SensorManager mSensorManager; private Sensor mLight; private RelativeLayout mLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mLayout = (RelativeLayout) findViewById(R.id.mLayout); mLayout.setKeepScreenOn(true); } @Override protected void onResume() { mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_FASTEST); super.onResume(); } @Override protected void onPause() { mSensorManager.unregisterListener(this); super.onPause(); } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { if (sensor.getType() == Sensor.TYPE_LIGHT) {
source share