我如何使用代码检查连接是通过Wifi还是GSM / GSM / 3G?
答案 0 :(得分:5)
从这里开始:Detect network connection type on Android
// 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;
}
答案 1 :(得分:0)
更好的是,您可以使用TelephonyManager。
PG::ConnectionBad
请查看此链接http://developer.android.com/reference/android/telephony/TelephonyManager.html