I am trying to turn off my screen programatically.
The following methods i have tried:
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);
The previous mentioned method does not work.
This however, works:
DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDPM.lockNow();
This works, but i am turning my screen off while the phone is ringing, and this causes the ringer to stop ringing. The same as if you are pressing the power button.
Well, i need to be able to turn off my display WITHOUT using DevicePolicyManager method. Or a way to set it that DevicePolicyManager method won't stop my device from ringing.
Thanks all!
its better to decrease the screen time out time to turn the screen off . like this :
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 10);
10 means 10 ms you can set your own !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With