电源控制(屏幕长亮)

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

   //电源控制权限
    

你可能感兴趣的:(电源控制(屏幕长亮))