我正在调用屏幕上,当用户正在通话时需要在屏幕上启用和禁用触摸事件。在android上禁用屏幕触摸通话
在此,我对我的行为实施SensorEventListener并覆盖onSensorChanged()方法:
public void onSensorChanged(SensorEvent sensorEvent) {
if(sensorEvent.sensor.getType() == Sensor.TYPE_PROXIMITY) {
if(sensorEvent.values[0] == 0) { //Sleep
sleepScreen(true);
} else { //Wake
sleepScreen(false);
}
}
}
下面是我sleepScreen()方法:
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);
}
}
的FLAG_NOT_TOUCHABLE工作正常禁用触摸事件。但是,我无法再次重新启用触摸事件。
请帮忙!
2014-11-04
Anirudh