android WiFi 开关代码
[java]/**
* 是否开启 wifi true:开启 false:关闭
*
* 一定要加入权限: <uses-permission
* android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
* <uses-permission
* android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
*
*
* @param isEnable
*/
public void setWifi(boolean isEnable) {
//
if (mWm == null) {
mWm = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
return;
}
System.out.println("wifi===="+mWm.isWifiEnabled());
if (isEnable) {// 开启wifi www.zzzyk.com
if (!mWm.isWifiEnabled()) {
mWm.setWifiEnabled(true);
}
} else {
// 关闭 wifi
if (mWm.isWifiEnabled()) {
mWm.setWifiEnabled(false);
}
}
}
补充:移动开发 , Android ,