Wifi和熱點(diǎn)不能同時(shí)開(kāi)啟:
因此在開(kāi)啟Wifi時(shí)需要先關(guān)閉熱點(diǎn),開(kāi)啟熱點(diǎn)時(shí)需要先關(guān)閉Wifi
開(kāi)啟和關(guān)閉熱點(diǎn):
/** * Wifi熱點(diǎn)開(kāi)關(guān). Wifi和熱點(diǎn)不能同時(shí)打開(kāi),所以打開(kāi)Wifi的時(shí)候需要關(guān)閉熱點(diǎn) * * @author jiangping.li * @return * @since MT 1.0 */ public boolean setWifiApEnabled(boolean enabled) { Method method1 = null; // 通過(guò)反射調(diào)用設(shè)置熱點(diǎn) Method method; try { method = mWifiManager.getClass().getMethod(setWifiApEnabled, WifiConfiguration.class, Boolean.TYPE); WifiConfiguration apConfig = null; if (enabled){ //開(kāi)啟熱點(diǎn),配置config,此處省略. apConfig = new WifiConfiguration(); .... .... } // 返回?zé)狳c(diǎn)設(shè)置狀態(tài) 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; }
開(kāi)啟和關(guān)閉wifi:
public boolean setWifiApEnabled(boolean enabled) { mWifiManager.setWifiEnabled(enabled); return enabled;}