Android: Turn screen on and off without locking

[亡魂溺海] 提交于 2019-12-05 17:10:48

There are two methods for doing that,

    PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);

// method 1
manager.goToSleep(int amountOfTime);

// method 2
PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Your Tag");
wl.acquire();// It will swith off
wl.release(); // And swith on

also add this permission,

<uses-permission android:name="android.permission.WAKE_LOCK" />
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!