Android: prevent display from turning off

前端 未结 4 1467
囚心锁ツ
囚心锁ツ 2021-01-02 10:05

I\'ve written a small game, that is only controlled via some sensors. There is no touchscreninput or something similar.

The problem is, that after a few seconds of g

4条回答
  •  北海茫月
    2021-01-02 10:36

    use WakeLock

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    WakeLock mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "My Tag");
    mWakeLock.acquire();
    

    and put the permission in your manifest file

    
    

    dont forget to release that lock in your onStop()

提交回复
热议问题