Android WiFi 电源管理
2010-03-12 15:37:00 来源:WEB开发网核心提示:mContext.getSystemService(Context.POWER_SERVICE);mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY);mWakeLock.setReferenceCounte
mContext.getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY);
mWakeLock.setReferenceCounted(true);
// Create a wifi lock
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mWifiLock = wifiManager.createWifiLock(WIFILOCK_KEY);
mWifiLock.setReferenceCounted(true);
}
private void acquire(){
// Acquire wake lock
mWakeLock.acquire();
// Acquire wifi lock
mWifiLock.acquire();
}
private void release(){
// Release wifi lock
mWifiLock.release();
// Release wake lock
mWakeLock.release();
}
}
[]
赞助商链接