Returns the ISO country code equivalent of the current registered operator's MCC (Mobile Country Code). - Android Android OS

Android examples for Android OS:OS Build

Description

Returns the ISO country code equivalent of the current registered operator's MCC (Mobile Country Code).

Demo Code


//package com.java2s;

import android.content.Context;

import android.telephony.TelephonyManager;

public class Main {
    /**/*w w w  .  j a va  2s  . c  om*/
     * Returns the ISO country code equivalent of the current registered
     * operator's MCC (Mobile Country Code).
     * <pre>
     * Availability: Only when user is registered to a network. Result may be
     * unreliable on CDMA networks to determine if on a CDMA network).
     * </pre>
     * <p>
     * Requires Permission:{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
     * @return
     */
    public static final String obtainNetworkCountryIso(Context context) {
        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        String country = tm.getNetworkCountryIso();
        if (country == null) {
            country = "";
        }
        return country;
    }
}

Related Tutorials