Android 螢幕喚醒

Android 螢幕喚醒Android 螢幕耗電, 擺低手機螢幕變暗,幷鎖定. 好似你唔惏野會放蚊咁.用『喚醒鎖』WakLock. 保持清醒『螢幕喚醒』.

  1. 先係『xml』添加權限
<uses-permission android:name=”android.permission.WAKE_LOCK” />
  1. 係『onCreate()』獲得電源管理『PowerManager』
PowerManager powerManager;
powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
  1. 生成『WakLock』喚醒鎖. 『FULL_WAKE_LOCK』螢幕保持著燈.CPU全速運行.
PowerManager.WakeLock wakeLock;
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, “WAKE LOCK”);
  1. 係『onResume()』啟用『WakLock』喚醒鎖, 手機保持喚醒態,
wakeLock.acquire();
  1. 係『onPause()』釋放喚醒鎖
wakeLock.release();

 

 

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

 

發表評論