WifiControl.setWifi(mContext, false);//关闭wifi
WifiControl.setWifi(mContext,true);//打开wifi
package com.wootec.gpiodetect;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.util.Log;
public class WifiControl {
static WifiManager mWm;
static boolean wifi_on = false;
public static void setWifi(Context context, boolean isEnable) {
//
if (mWm == null) {
mWm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
return;
}
Log.e("wuyb", "wuyb----wifi===="+mWm.isWifiEnabled());
if (isEnable) {// 开启wifi
if(wifi_on)
{
if (!mWm.isWifiEnabled()) {
mWm.setWifiEnabled(true);
}
wifi_on = false;
}
} else {
// 关闭 wifi
if (mWm.isWifiEnabled()) {
wifi_on = true;
mWm.setWifiEnabled(false);
}
}
}
}
wifi打开关闭工具类
最新推荐文章于 2018-10-07 20:01:54 发布