我需要使用 SensorEventListener 打开/关闭屏幕
@Override
public final void onSensorChanged(SensorEvent event) {
if (event.values[0] == 0)
turnScreenOFF();
else if (event.values[0] == 5)
turnScreenON();
}
我已经为此尝试了许多示例代码,但是在关闭屏幕后我无法再次打开屏幕
有关闭屏幕的代码:
WindowManager.LayoutParams params = getWindow().getAttributes();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
params.screenBrightness = 0.0f;
getWindow().setAttributes(params);