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.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;

public class Main {
    public static String checkNetType(Context context) {
        ConnectivityManager connectMgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = connectMgr.getActiveNetworkInfo();
        String type = "no_network";
        if (info == null) {
            return type;
        }
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            type = "wifi";
        } else {
            switch (info.getSubtype()) {
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
                type = "UNKNOWN";
                break;
            case TelephonyManager.NETWORK_TYPE_GPRS:
                type = "GPRS";
                break;
            case TelephonyManager.NETWORK_TYPE_EDGE:
                type = "EDGE";
                break;
            case TelephonyManager.NETWORK_TYPE_UMTS:
                type = "UMTS";
                break;
            case TelephonyManager.NETWORK_TYPE_CDMA:
                type = "CDMA";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
                type = "EVDO_0";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
                type = "EVDO_A";
                break;
            case TelephonyManager.NETWORK_TYPE_1xRTT:
                type = "1xRTT";
                break;
            case TelephonyManager.NETWORK_TYPE_HSDPA:
                type = "HSDPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSUPA:
                type = "HSUPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSPA:
                type = "HSPA";
                break;
            case TelephonyManager.NETWORK_TYPE_IDEN:
                type = "IDEN";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
                type = "EVDO_B";
                break;
            case TelephonyManager.NETWORK_TYPE_LTE:
                type = "LTE";
                break;
            case TelephonyManager.NETWORK_TYPE_EHRPD:
                type = "EHRPD";
                break;
            case TelephonyManager.NETWORK_TYPE_HSPAP:
                type = "HSPAP";
                break;
            }
        }
        return type;
    }
}