Code example for NetworkInfo

Methods: getSubtype, getType, getTypeName, isRoaming

0
        NetworkInfo info = cManager.getActiveNetworkInfo();
        if (info==null) {
            Log.i("NetworkHelper", "Can't get info about active network, blocking down load");
            return false; 
        } 
        int type = info.getType();
        int subType = info.getSubtype();
 
        int configType;
        try { 
            configType = Integer.parseInt(networkConfig);
        } catch (NumberFormatException e) {
            Log.w("NetworkHelper",e.getMessage());
            configType = 6;
        } 
        if (configType==6) // Never
            return false; 
        if (configType==1)
            return true; // Always 
 
        if (type== ConnectivityManager.TYPE_MOBILE) {
            if (info.isRoaming() && !whenRoaming) {
                Log.d("NetworkHelper","Phone is roaming, but download disabled ");
                return false; 
            } 
 
            switch (configType) {
                case 1: return true;  // Always 
                case 2: return false; // WiFi necessary - but this is a mobile network 
                case 3: return subType > TelephonyManager.NETWORK_TYPE_UMTS;
                case 4: return subType >= TelephonyManager.NETWORK_TYPE_EDGE;
                case 5: return subType >= TelephonyManager.NETWORK_TYPE_GPRS;
                case 6: return false; // Never 
                default: 
                    Log.w("NetworkHelper","Unknown config type: " + configType);
                    return false; 
            } 
 
        } else if (type==ConnectivityManager.TYPE_WIFI && configType==2) {
            return true; // Wifi is 'better' than mobile and 'Never' was caught earlier 
        } else { 
            Log.i("NetworkHelper","Unknown connectivity type: " + info.getTypeName());
            return false; 
        } 
    } 
 
    public boolean isOnline() {