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

	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();
	}

猜你喜欢

转载自zhouxi1987.iteye.com/blog/1859932