How to make android device always in wake mode?

后端 未结 7 1276
名媛妹妹
名媛妹妹 2021-02-07 04:46

After successful root of device. Now, I need to make device always in wake state i.e. always visibility of UI and no black screen or any daydream screens. To do so I think I\'ve

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 05:03

    To prevent the sleep mode on a specific View, just call setKeepScreenOn(true) on that View or set the keepScreenOn property to true.

    In turns it will prevent the screen from going off while the View is on the screen. It works without requiring the WAKE_LOCK permission (or any special permission) , which is a better practice here.

    Also this will not force the phone to stay awake outside the life span of the application. You can run into that problem with WakeLock

    You can integrate the above method with another approach to get the full solution (outside an application layer):

    From the root shell (e.g. adb shell), you can lock with:

    echo mylockname >/sys/power/wake_lock 
    
    After which the device will stay awake, until you do:
    
    echo mylockname >/sys/power/wake_unlock    
    

    With the same string for 'mylockname'.

    Note that this will not prevent the screen from going black, but it will prevent the CPU from sleeping.

    Note that /sys/power/wake_lock is read-write for user radio (1001) and group system (1000), and, of course, root.

    Source: https://lwn.net/Articles/479841/

    Source: https://stackoverflow.com/a/18968753/3125120

提交回复
热议问题