Android笔记-开启和关闭wifi的代码段
1、需要申请的权限
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.WAKE_LOCK
2、获取WifiManager
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
3、开启、关闭wifi
if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
} else {
wifiManager.setWifiEnabled(true);
}
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.WAKE_LOCK
2、获取WifiManager
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
3、开启、关闭wifi
if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
} else {
wifiManager.setWifiEnabled(true);
}
本文出自 小古Blog,转载时请注明出处及相应链接。
本文永久链接: http://blog.chdz1.com/?post=238