public static WifiHotspotState getWifiHotspotState(final Context pContext) throws WifiUtilsException { final WifiManager wifiManager = WifiUtils.getWifiManager(pContext); try { final Method WifiManager_getWifiApState = wifiManager.getClass().getMethod("getWifiApState"); if (WifiManager_getWifiApState == null) { throw new WifiUtilsException( new MethodNotFoundException(WifiManager.class.getSimpleName() + ".getWifiApState()")); } else { final int result = (Integer) WifiManager_getWifiApState.invoke(wifiManager); return WifiHotspotState.fromWifiApState(result); } } catch (final Throwable t) { throw new WifiUtilsException(t); } }
public static WifiHotspotState fromWifiApState(final int pWifiApState) throws WifiUtilsException { if (SystemUtils.isAndroidVersionOrHigher(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) { switch (pWifiApState) { case 10: return DISABLING; case 11: return DISABLED; case 12: return ENABLING; case 13: return ENABLED; case 14: return FAILED; default: throw new WifiUtilsException("TODO..."); } } else { switch (pWifiApState) { case 0: return DISABLING; case 1: return DISABLED; case 2: return ENABLING; case 3: return ENABLED; case 4: return FAILED; default: if (pWifiApState >= 10) { return WifiHotspotState.fromWifiApState(pWifiApState - 10); } else { throw new WifiUtilsException("TODO..."); } } } }