How to turn screen off or send device to sleep

后端 未结 2 1357
无人共我
无人共我 2020-12-31 08:57

I want to send device to sleep or turn the screen off. I have investigated and found this topic: Turn off screen on Android

Basically, the are three ways to do it, b

2条回答
  •  猫巷女王i
    2020-12-31 09:33

    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) {
        }
    }
    

提交回复
热议问题