Android 强制2G/3G或WIFI 优先上网
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();
}
相关推荐
crazymaple 2012-03-19
xilove0 2020-03-03
ruanjianxiong 2011-03-30
xdhywj 2012-08-21
whale 2019-06-21
xuweinet 2019-06-21
yuemeng0 2012-07-05
Urchindong 2012-02-27
luoj 2012-02-22
wukunting 2011-06-28
huzhenv 2011-05-04
lizhen00 2011-03-05
zjwijy 2013-02-18