Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.telephony.TelephonyManager;

public class Main {
    public static String getNetworkTypeName(int type) {
        String name = "Unknown";
        switch (type) {
        case TelephonyManager.NETWORK_TYPE_GPRS:
            name = "GPRS";
            break;
        case TelephonyManager.NETWORK_TYPE_EDGE:
            name = "EDGE";
            break;
        case TelephonyManager.NETWORK_TYPE_CDMA:
            name = "CDMA";
            break;
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            name = "EVDO_0";
            break;
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            name = "EVDO_A";
            break;
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            name = "HSDPA";
            break;
        case TelephonyManager.NETWORK_TYPE_HSPA:
            name = "HSPA";
            break;
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            name = "HSUPA";
            break;
        case TelephonyManager.NETWORK_TYPE_UMTS:
            name = "UMTS";
            break;
        default:
        }

        return name;
    }

    public static String getNetworkTypeName(Context context) {
        int kind = 0;
        try {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            kind = tm.getNetworkType();
        } catch (Exception e) {

        }
        return String.valueOf(kind);
    }
}