I want to turn screen ON and OFF based on the proximity sensor. I am able to turn the screen off. but the code to ON the screen back is not working. Can anyone help me please? This is the code:`
public void onSensorChanged(SensorEvent event) {
if (event.values[0] == 0) {
Toast.makeText(getApplicationContext(), "sensor in 0",Toast.LENGTH_LONG).show();
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
getWindow().setAttributes(params);
} else {
Toast.makeText(getApplicationContext(), "sensor in 1",Toast.LENGTH_LONG).show();
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = -1;
getWindow().setAttributes(params);
}
}`
First I dimmed screen brightness as low as possible and then made all GUI elements unclickable for touch issues. Following is my code:
From here, I took reference to disable touch for entire screen's view.