private void toggleWifi() { if (mWifiManager == null) { mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); } int state = mWifiManager.getWifiState(); int apState = mWifiManager.getWifiApState(); if (state == WifiManager.WIFI_STATE_ENABLING || state == WifiManager.WIFI_STATE_DISABLING) { return; } if (apState == WifiManager.WIFI_AP_STATE_ENABLING || apState == WifiManager.WIFI_AP_STATE_DISABLING) { return; } if (state == WifiManager.WIFI_STATE_ENABLED || apState == WifiManager.WIFI_AP_STATE_ENABLED) { mWifiManager.setWifiEnabled(false); mWifiManager.setWifiApEnabled(null, false); notifyKey(ASUSDEC_WIFI, ASUSDEC_STATUS_OFF); } else if (state == WifiManager.WIFI_STATE_DISABLED && apState == WifiManager.WIFI_AP_STATE_DISABLED) { mWifiManager.setWifiEnabled(true); notifyKey(ASUSDEC_WIFI, ASUSDEC_STATUS_ON); } }
@Override public int getActualState(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { return wifiApStateToFiveState(wifiManager.getWifiApState()); } return STATE_UNKNOWN; }