2011-07-19 137 views

回答

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; 
} 
相關問題