我已经在代码中成功配置了Proximeter。现在我想以编程方式关闭和打开屏幕。传感器代码工作正常,下面的方法也被调用。

@Override
public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    WakeLock screenWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"screenWakeLock");

    if (event.values[0] == 0) {
        screenWakeLock.acquire();
        Log.e("onSensorChanged","NEAR");
    } else {
        if (screenWakeLock != null) {
               if(screenWakeLock.isHeld())
                  screenWakeLock.release();
               screenWakeLock = null;
        }
        Log.e("onSensorChanged","FAR");
    }
}

我的问题是屏幕没有关。我还在代码中添加了必需的权限。还有什么原因???

最佳答案

检查为此代码提交的更改,https://github.com/jitsi/jitsi-android/compare/6d356fa637ae...7aba481d773f

getPowerManager().newWakeLock( 32, "proximity_off");

10-08 07:51