title: Disable screen touch in android on call
body: <p>I am working on a calling screen where I need to enable and disable touch events on the screen while the user is on a call.</p>
  
  <p>For this I implement SensorEventListener on my activity and override the onSensorChanged() method:</p>
  
  <pre><code>public void onSensorChanged(SensorEvent sensorEvent) {
      if(sensorEvent.sensor.getType() == Sensor.TYPE_PROXIMITY) {
          if(sensorEvent.values[0] == 0) { //Sleep
              sleepScreen(true);
          } else { //Wake
              sleepScreen(false);
          }
      }
  }
  </code></pre>
  
  <p>Below is my sleepScreen() method:</p>
  
  <pre><code>protected void sleepScreen(boolean on){
      if(on == true) {
          WindowManager.LayoutParams params = getWindow().getAttributes();
          params.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
          getWindow().setAttributes(params);
      } else {
          WindowManager.LayoutParams params = getWindow().getAttributes();
          params.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
          getWindow().setAttributes(params);
      }
  
  }
  </code></pre>
  
  <p>The FLAG_NOT_TOUCHABLE works fine disabling touch events. However, I am not able to re-enable the touch events again.</p>
  
  <p>Pls help!</p>