2012년 6월 11일 월요일

[Android] idle(sleep) mode 방지 코드...

private static PowerManager.WakeLock fullWakeLock;

PowerManager pm = (PowerManager) m_sInstance.getSystemService(Context.POWER_SERVICE);
fullWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "GangstarGreeActivity");
keepScreenOn(true);


public static boolean keepScreenOn(boolean keep)
{
  if (keep && !fullWakeLock.isHeld())
  {
    if (fullWakeLock != null)
    {
      fullWakeLock.acquire();
      return true;
    }
  }
  else if (!keep && fullWakeLock.isHeld())
  {
    if (fullWakeLock != null)
    {
      fullWakeLock.release();
      return true;
    }
  }
 
  return false;
}

댓글 없음:

댓글 쓰기