Search code examples
androidtelephonymanager

What is the easiest way to get standard network type on Android?


I know how to Get Network type. But I need to identify the related standard to each release, grouping by GSM, WCDMA and LTE (others standards will not be used). I could filter it like this:

switch (networkType) {
    case TelephonyManager.NETWORK_TYPE_GPRS:
        tech = "GPRS";
        standard = "GSM";
        break;
    case TelephonyManager.NETWORK_TYPE_HSDPA:
        tech = "HSDPA";
        standard = "WCDMA";
        break;
}

Is there some information from Android API that I can use to retrieve this information on a elegant way?

It will help me to work with some information about mobile netowrk that is handle in diffrent ways between WCDMA, LTE and GSM.

UPDATE: It is not exactly what I am asking, but is very near. How to determine if network type is 2G, 3G or 4G


Solution

  • Use NetworkInfo.

    For instance, here you are a method which gives you if a device has or not network.

    public Boolean hasDeviceConnectionToInternet(Context context) {
            ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo i = conMgr.getActiveNetworkInfo();
            if (i == null)
                return false;
            if (!i.isConnected())
                return false;
            if (!i.isAvailable())
                return false;
            return true;
        }
    

    For your case, you can ask i.getType() for getting the connection type, or i.getTypeName() for a human-readable description.

    You can see API here: http://developer.android.com/reference/android/net/NetworkInfo.html