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