电源控制(屏幕长亮)

2019-07-14 02:42发布

1. 主Activity

(1)声明: public PowerManager pm; public PowerManager.WakeLock mWakeLock; (2)onCreate中调用自定义的initData(): pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "myLock"); (3)onResume(): mWakeLock.acquire(); (4)onPause()或者onDestroy():根据具体情况 mWakeLock.release();

2. AndroidManifest

//电源控制权限