Managing Device Awake State

Keeping the Device Awake

Keep the Screen On

  • onCreate()中
    getWindow.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
  • layout XML中
    android:keepScreenOn = "true"

Keep the CPU On

使用PowerManager
permission --- WAKE_LOCK
wakeLock.acquire()
wakeLock.release()

Using WakefulBroadcastReceiver

PARTIAL_WAKE_LOCK

  • add WakefulBroadcastReceiver to manifest
  • onReceive() --- startWakefulService
  • release the wake lock

Scheduling Repeating Alarms

你可能感兴趣的:(Managing Device Awake State)