How to make android device always in wake mode?

后端 未结 7 1452
名媛妹妹
名媛妹妹 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:21

    Your main use case appears to be as follows (from your question)

    Even if some other applications try to change above functionalities then they should not be able to do so

    You can write a system service to trigger the PowerManager.WakeLock at regular intervals. (Source)

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
    wl.acquire();
    
    // screen and CPU will stay awake during this section
    
    wl.release();
    

    To optimize the service you can also try setting the screen timeout the the maximum possible again at regular intervals so that even if changed manually it gets reset. (not sure how much max is allowed, you'll need to check with trial and error)

      /**
       * set screen off timeout
       * @param screenOffTimeout int 0~6
       */
    private void setTimeout(int screenOffTimeout) {
        int time;
        switch (screenOffTimeout) {
        case 0:
            time = 15000;
            break;
        case 1:
            time = 30000;
            break;
        case 2:
            time = 60000;
            break;
        case 3:
            time = 120000;
            break;
        case 4:
            time = 600000;
            break;
        case 5:
            time = 1800000;
            break;
        default:
            time = -1;
        }
        android.provider.Settings.System.putInt(getContentResolver(),
                Settings.System.SCREEN_OFF_TIMEOUT, time);
    }
    

    (Source)

提交回复
热议问题