简体   繁体   中英

How Do I Make The Phone Go To Sleep?

I have an application and instead of keeping the screen on, once the app runs I want the screen to go dark. How do I do this? I know that to make the screen stay on I do this:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

But I cannot find out how to make the screen go dark.

check this http://rdcworld-android.blogspot.com/2012/03/lock-phone-screen-programmtically.html

OR Try this one

WindowManager wm = Context.getSystemService(Context.WINDOW_SERVICE);   

//Lock device  
DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDPM .lockNow();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM