get Country name from TelephonyManager - Android Internationalization

Android examples for Internationalization:Locale

Description

get Country name from TelephonyManager

Demo Code


//package com.java2s;

import android.content.Context;

import android.telephony.TelephonyManager;

public class Main {
    public static String getCountry(Context context) {
        String imsi = getIMSI(context);
        String mcc = "0";
        if (null != imsi && imsi.trim().length() > 0) {
            mcc = imsi.substring(0, 3);/*from  w  w  w . ja  va2 s  .co  m*/
        }
        return mcc;
    }

    private static String getIMSI(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        String imsi = telephonyManager.getSubscriberId();
        return imsi;
    }
}

Related Tutorials