如何使用代码检查是否通过 Wifi 或 Android 中的 GSM/3G 建立连接?
问问题
1028 次
2 回答
5
// Only update if WiFi or 3G is connected and not roaming
int netType = info.getType();
int netSubtype = info.getSubtype();
if (netType == ConnectivityManager.TYPE_WIFI) {
return info.isConnected();
} else if (netType == ConnectivityManager.TYPE_MOBILE
&& netSubtype == TelephonyManager.NETWORK_TYPE_UMTS
&& !mTelephony.isNetworkRoaming()) {
return info.isConnected();
} else {
return false;
}
于 2011-07-19T07:55:18.710 回答
0
更好的是,您可以使用 TelephonyManager。
TelephonyManager tm = (TelephonyManager)
getSystemService(TELEPHONY_SERVICE);
String operatorname = tm.getNetworkOperatorName();
请检查此链接http://developer.android.com/reference/android/telephony/TelephonyManager.html
于 2015-06-05T06:25:07.430 回答