Code example for NetworkInfo

Methods: getType

0
        ConnectivityManager cm =
            (ConnectivityManager)sInstance.mApplicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm == null) {
            Log.e(LOGTAG, "Connectivity service does not exist");
            return NetworkType.NETWORK_NONE;
        } 
 
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if (ni == null) {
            return NetworkType.NETWORK_NONE;
        } 
 
        switch (ni.getType()) {
        case ConnectivityManager.TYPE_ETHERNET:
            return NetworkType.NETWORK_ETHERNET;
        case ConnectivityManager.TYPE_WIFI:
            return NetworkType.NETWORK_WIFI;
        case ConnectivityManager.TYPE_WIMAX:
            return NetworkType.NETWORK_WIMAX;
        case ConnectivityManager.TYPE_MOBILE:
            break; // We will handle sub-types after the switch.