title: Android: How to detect if the light sensor of android is covered by hand
body: <p>I am a new Android developer and working on a fun project. I want to make the cell phone beeps for couple of seconds if the light sensor is covered. But I don't know what event is triggered when the light sensor is covered. Can some one give me a hint please what that event would be ?</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
      SensorManager sensorManager = (SensorManager) this.getSystemService(this.SENSOR_SERVICE);
      Sensor lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
      ( some event ???) {
      // if some one coveres the light sensor then beep sound is played         
          ToneGenerator toneGen1 = new ToneGenerator(AudioManager.STREAM_MUSIC, 200);
          toneGen1.startTone(ToneGenerator.TONE_CDMA_ABBR_REORDER,15000);
  
      }
      if (lightSensor != null){
          Toast.makeText(this, "There is a sensor light ",
                  Toast.LENGTH_SHORT).show();
  
  
      }
      else {
          // Failure! sensor not available.
          Toast.makeText(this, "No sensor light",
                  Toast.LENGTH_SHORT).show();
      }
  
  
  }
  </code></pre>
  
  <p>}</p>