How to Manage Screen On/Off Functionality
Screen on/off
Here is the snippet code:
private void goToLockNow() {
try {
boolean result = systemExtApi.setDeviceOwner(this.getPackageName(),LockReceiver.class.getName());
if(result){
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
devicePolicyManager.lockNow();
SystemClock.sleep(2000);
mWakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass().getName());
wakeUp();
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
/**
* Wake up screen
*/
private void wakeUp() {
mWakeLock.acquire();
if (mWakeLock.isHeld()) {
mWakeLock.release();
}
}