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;

public class Main {
    public static final int MOBILE_SERVICE_CM = 100;
    public static final int MOBILE_SERVICE_UN = 101;
    public static final int MOBILE_SERVICE_CT = 102;
    public static final int MOBILE_SERVICE_UNKNOW = 103;

    public static int getMobileService(Context context) {
        ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info2 = conn.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (info2 == null || info2.getExtraInfo() == null) {
            return MOBILE_SERVICE_UNKNOW;
        }
        String info = info2.getExtraInfo().toLowerCase();
        // //3gnet/3gwap/uninet/uniwap/cmnet/cmwap/ctnet/ctwap
        if ("3gwap".equals(info) || "3gnet".equals(info) || "uninet".equals(info) || "uniwap".equals(info)
                || "3gwap".equals(info)) {
            return MOBILE_SERVICE_UN;
        } else if ("cmnet".equals(info) || "cmwap".equals(info)) {
            return MOBILE_SERVICE_CM;
        } else if ("ctnet".equals(info) || "ctwap".equals(info)) {
            return MOBILE_SERVICE_CT;
        } else {
            return MOBILE_SERVICE_UNKNOW;
        }
    }
}