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.content.Context;

import android.telephony.TelephonyManager;

public class Main {
    private static String operatorCode;
    private static String isoCountryCode;

    public static String queryDevicePhone(Context context) {
        TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (manager != null) {
            operatorCode = manager.getNetworkOperator();
            if (operatorCode == null || operatorCode.length() == 0)
                operatorCode = manager.getSimOperator();
            isoCountryCode = manager.getNetworkCountryIso();
            if (isoCountryCode == null || isoCountryCode.length() == 0)
                isoCountryCode = manager.getSimCountryIso();
            if (isoCountryCode == null || isoCountryCode.length() == 0)
                isoCountryCode = context.getResources().getConfiguration().locale.getCountry();
        }
        return manager.getLine1Number();
    }
}