Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.app.Service;
import android.content.Context;

import android.telephony.TelephonyManager;

public class Main {
    /**
     * get mobile operator
     * 
     * @param context
     * @return
     */
    public static String getMobileCarrier(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
        if (tm.getSubscriberId() != null && tm.getSubscriberId().trim().length() >= 5) {
            return tm.getSubscriberId().substring(0, 5);
        } else {
            return "";
        }
    }

    protected static String substring(String s, int from) {
        try {
            return s.substring(from);
        } catch (Exception e) {

        }
        return "";
    }

    protected static String substring(String s, int from, int len) {
        try {
            return s.substring(from, from + len);
        } catch (Exception e) {

        }
        return "";
    }
}