How to turn screen off or send device to sleep

泪湿孤枕 提交于 2019-11-30 11:45:57
Tibor

I answer myself. It is possible to turn off the device, but the application has to implement the device administrator feature via API: Device Administration

In this API there is a locknow() function that do what I want.

Anyway, this is for extending the android hardware and security features and it is very unlikely that anyone wants to control the device in that way.

What I wanted is the ability to lock the device from a simple gesture. As I dont want to make my own device manager class I check if the free application "lockScreen" is installed and launch it. It is a shortcut and an easy way to do what I want. This app must be register as device manager so it has implemented this class. It is possible to get it free from the market.

hamish

My application already does this fine, I found this in my PowerManager.class

 /**
 * Force the device to go to sleep. Overrides all the wake locks that are
 * held.
 * 
 * @param time is used to order this correctly with the wake lock calls. 
 *          The time  should be in the {@link SystemClock#uptimeMillis 
 *          SystemClock.uptimeMillis()} time base.
 */
public void goToSleep(long time) 
{
    try {
        mService.goToSleep(time);
    } catch (RemoteException e) {
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!