WiFi and hotspot cannot be turned on at the same time:
So when you turn on WiFi, you need to close the hotspot first, turn off the WiFi
To turn hotspots on and off:
/** * WiFi hotspot switch. WiFi and hotspot cannot be opened at the same time, so you need to turn off hotspot when WiFi is turned on * * @author jiangping.li * @return * @since MT 1.0 * * Public Boole An setwifiapenabled (Boolean enabled) {Method method1 = null; Set hot Spot method by reflection call; try {method = Mwifimanager.getclass (). GetMethod ("setwifiapenabled", Wificonfiguration.class , Boolean.type); Wificonfiguration apconfig = null; if (enabled) {//open hotspot, configure Config, omitted here. Apconfig = new Wificonfiguration (); .... .... } Returns the Hotspot setting state 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; }
To turn WiFi on and off:
Public Boolean setwifiapenabled (Boolean enabled) { mwifimanager.setwifienabled (enabled); return enabled;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Mutually exclusive relationships When you turn on WiFi and hotspots