Android 强制2G/3G或WIFI 优先上网

2014-11-24 08:32:23 · 作者: · 浏览: 2

public void setPreferredNetwork(int networkType) {
ConnectivityManager connMgr = (ConnectivityManager) this.context.getSystemService("connectivity");
if (networkType == NetworkType.TYPE_MOBILE) {//设为2G/3G网络优先,就算wifi连接到AP,系统仍然通过2G/3G访问网络
connMgr.setNetworkPreference(0);
} else if (networkType == NetworkType.TYPE_WIFI) {
connMgr.setNetworkPreference(1);

}
WifiManager wifiMgr = (WifiManager) this.context.getSystemService("wifi");
wifiMgr.disconnect();
}