Android关掉屏幕,需要用PowerManager ,并声明相关权限。
-
获取电源管理器PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); -
设置相关api pm.goToSleep(SystemClock.uptimeMillis()); PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "TAG"); wakeLock.acquire(); wakeLock.release(); -
声明相关权限
<uses-permission android:name="android.permission.WAKE_LOCK" /> <user-permission android:name="android.permission.DEVICE_POWER"/> |