在Android中,我怎样才能关闭屏幕编程? [英] In android, how can i turn off the screen programatically?
问题描述
我试图关闭我的屏幕编程。
I am trying to turn off my screen programatically.
下面的方法我都试过:
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);
在previous提到的方法是行不通的。
The previous mentioned method does not work.
然而,这作品:
DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDPM.lockNow();
这工作,但我把我的屏幕,同时手机响了,这会导致振铃停止振铃。同样的,如果你是pressing电源按钮。
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.
嗯,我需要能够关闭我的显示不使用DevicePolicyManager方法。或方式来进行设置的DevicePolicyManager方法不会振铃停止我的设备。
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.
谢谢大家!
推荐答案
其更好地降低屏幕超时时间来关闭屏幕。 像这样的:
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表示10毫秒,你可以设置你自己!
10 means 10 ms you can set your own !
这篇关于在Android中,我怎样才能关闭屏幕编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!