Registers a SensorEventListener for the given sensor.
Note: Don't use this method with a one shot trigger sensor such as TYPE_SIGNIFICANT_MOTION. Use requestTriggerSensor(TriggerEventListener, Sensor) instead.
listener - A SensorEventListener object.
sensor - The Sensor to register to.
rateUs - The rate sensor events are delivered at. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. The value must be one of SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, SENSOR_DELAY_GAME, or SENSOR_DELAY_FASTEST or, the desired delay between events in microseconds. Specifying the delay in microseconds only works from Android 2.3 (API level 9) onwards. For earlier releases, you must use one of theSENSOR_DELAY_* constants.
Returns: true if the sensor is supported and successfully enabled.
1. Determine if Android Device has Light Sensor, using SensorManager with SensorManager named mySensorManager, a Sensor named mySensor.
2. Add a SensorEventListener named mySensorEventListener.
3. Add the line below to the onCreate method. This will register the SensorEventListener named mySensorEventListener to the Sensor named mySensor, at a rate of Normal Delay.
mySensorManager.registerListener(mySensorEventListener, mySensor, SensorManager.SENSOR_DELAY_NORMAL);
4. Compile and run!
5. You can use the below options to change the sensor delay.
SENSOR_DEALY_NORMAL - rate (default) suitable for screen orientation changes
SENSOR_DELAY_UI - rate suitable for the user interface
SENSOR_DELAY_GAMES - rate suitable for games
SENSOR_DELAY_FASTEST - get sensor data as fast as possible
Resources:http://developer.android.com/reference/android/hardware/SensorManager.html#registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int)