7

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!

1 Answer 1

1

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 !

3
  • That does not work as if there is a wake lock active then it will never time out. The DevicePolicyManager method i mentioned above is the proper way to turn off a display, just doesn't work perfectly in my situation.
    – Seth
    Oct 21, 2013 at 1:31
  • but his not work for every devices . in my idea the best way is here
    – M410
    Oct 21, 2013 at 8:25
  • That link you posted is exactly what i just said.. i don't understand what you are trying to say? So long as your device is 2.2 (API 8) or newer, you can use DevicePolicyManager and mDPM.lockNow() to turn off your screen.
    – Seth
    Oct 22, 2013 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.