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
//电源控制权限
<uses-permission android:name="android.permission.WAKE_LOCK"/>
网友评论