最近几天我一直在环顾四周,所提出的问题的答案都没有帮助我,我正在用一些可能很容易解决的东西撞到我的头......我想使用接近传感器和我正在做的是,如果我将手指放在传感器上,它会关闭屏幕,如果我将手指移开,它会重新回到屏幕上!我成功地关闭了屏幕,当我移开手指时收到“Log.i("info", "trying to turn on!")”消息,但不知何故屏幕无法打开...... .我试过wakelock(评论)和没有成功的标志!如果我移开手指,键盘上的灯会亮,但屏幕不会.. 如果我按两次电源按钮,它会成功打开屏幕!有人可以帮我吗?:(
@Override
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType()==Sensor.TYPE_PROXIMITY){
ProximityReading.setText("\nProximity Sensor Reading:" + String.valueOf(event.values[0]));
}
if(event.values[0] == 0) {
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 = 0f;
getWindow().setAttributes(params);
} else {
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 1f;
getWindow().setAttributes(params);
/*powermanager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powermanager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wakeLock.acquire();
Log.i("info", "trying to turn on!");
}
}