I have a problem using the proximity sensor to turn off the screen. When My Device uses SDK version 21 or higher, I can use this code to turn off the screen when the user puts the phone next to something. (Capture SensorEventListener events)
public void turnOnScreen(){
Log.v("ProximityActivity", "ON!");
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
mWakeLock.acquire();
}
@TargetApi(21)
public void turnOffScreen(){
Log.v("ProximityActivity", "OFF!");
mWakeLock = mPowerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
mWakeLock.acquire();
}
Now the problem is that I don’t know how to get the same behavior before API 21. I would like to put the screen in black and turn off all events on it.
Thanks in advance.
source
share