private ContentObserver mWifiObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
int value = Settings.System.getInt(
mContext.getContentResolver(), Settings.Global.WIFI_SLEEP_POLICY, Settings.Global.WIFI_SLEEP_POLICY_NEVER);
if(value != Settings.Global.WIFI_SLEEP_POLICY_NEVER){
if(mWakeLock!=null){
if(mWakeLock.isHeld())
mWakeLock.release();
mWakeLock = null;
}
}else{
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()){
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WifiEnableWakeLock");
mWakeLock.acquire();
}
}
}
};
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.Global.WIFI_SLEEP_POLICY),
false, mWifiObserver);