1.获取WIFI_SERVICE
wifiManager = (WifiManager)WifiActivity.this.getSystemService(Context.WIFI_SERVICE);
2.判断Wifi是否打开
wifiManager .isWifiENabled();
3.打开Wifi
wifiManager.setWifiEnabled(true);
4.关闭Wifi
wifiManager.setWifiEnabled(false);
5.获取Wifi状态
wifiManager.getWifiState();
6.使用wifi访问网络所需要的权限
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>