Wifi和热点不能同时开启:
因此在开启Wifi时需要先关闭热点,开启热点时需要先关闭Wifi
开启和关闭热点:
/** * Wifi热点开关. Wifi和热点不能同时打开,所以打开Wifi的时候需要关闭热点 * * @author jiangping.li * @return * @since MT 1.0 */ public boolean setWifiApEnabled(boolean enabled) { Method method1 = null; // 通过反射调用设置热点 Method method; try { method = mWifiManager.getClass().getMethod(setWifiApEnabled, WifiConfiguration.class, Boolean.TYPE); WifiConfiguration apConfig = null; if (enabled){ //开启热点,配置config,此处省略. apConfig = new WifiConfiguration(); .... .... } // 返回热点设置状态 return (Boolean)method.invoke(mWifiManager, apConfig, false); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return true; }
开启和关闭wifi:
public boolean setWifiApEnabled(boolean enabled) { mWifiManager.setWifiEnabled(enabled); return enabled;}