I have configured proximeter successfully in my code. Now I want to turn off & on screen programmatically. Code of sensor is working just fine and following method is also getting called.
@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");
}
}
My problem is that screen is not getting turn off. I also have added required permission in code. What else could be the reason ???
Check the changes submitted for this code, https://github.com/jitsi/jitsi-android/compare/6d356fa637ae...7aba481d773f
getPowerManager().newWakeLock( 32, "proximity_off");