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 final static int PROVIDER_UNKNOWN = 0;
    public final static int CHINA_MOBILE = 1;
    public final static int CHINA_UNICOM = 2;
    public final static int CHINA_TELECOM = 3;

    public static int getProvider(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String IMSI = telephonyManager.getSubscriberId();
        if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
            return CHINA_MOBILE;
        } else if (IMSI.startsWith("46001")) {
            return CHINA_UNICOM;
        } else if (IMSI.startsWith("46003")) {
            return CHINA_TELECOM;
        }
        return PROVIDER_UNKNOWN;
    }
}