I want to implement some code lines that allow Android turn on/off screen like we quick turn on/off device by using Power button. Is there any way to do that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It seems you want to lock the device not turn it off. To lock the device its a simple code. Mentioned here
It uses device Policy Manager
lockNow()methodIn case of a RuntimeError use the method described in this question to set permissions
Android DevicePolicyManager lockNow()
http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html
To switch off the device:
This is not possible but you can reboot it using PowerManager
http://developer.android.com/reference/android/os/PowerManager.html#reboot
Note this requires REBOOT permission and OS may cancel it.