As from my understanding wakelock
is useful to keep screen on. I wasn't successful to turn screen on & off using it.
So, first I dimmed screen brightness as low as possible and then made all GUI elements unclickable. This way I solved my problem.
Following is method:
@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
WindowManager.LayoutParams params = this.getWindow().getAttributes();
if (event.values[0] == 0) {
//TODO Store original brightness value
params.screenBrightness = 0.004f;
this.getWindow().setAttributes(params);
enableDisableViewGroup((ViewGroup)findViewById(R.id.YOUR_MAIN_LAYOUT).getParent(),false);
Log.e("onSensorChanged","NEAR");
} else {
//TODO Store original brightness value
params.screenBrightness = -1.0f;
this.getWindow().setAttributes(params);
enableDisableViewGroup((ViewGroup)findViewById(R.id.YOUR_MAIN_LAYOUT).getParent(),true);
Log.e("onSensorChanged","FAR");
}
}
From here, I took reference to disable touch for entire screen's view.