Namespaces
Variants
Actions

Getting Mobile country code (MCC) in Java ME

Jump to: navigation, search
SignpostIcon MobilePhone 52.png
Article Metadata

Compatibility
Device(s): Java enabled phone supporting JSR-179

Article
Keywords: Mobile Country Code
Created: prssupe (09 May 2011)
Last edited: hamishwillee (11 Nov 2011)

This article shows how to get the mobile country code (MCC) using J2ME

MOBILE COUNTRY CODE

Mobile country code (MCC) is a unique code assigned for each country, frequently related to the list of Mobile Network Code (MNC), and used to get the list of all country codes. A possible and useful usage of MCC is localization, allowing the programmer to modify your applications look and feel based on country's localization. To use MCC in your application, the device should support Location API for J2ME, described in JSR-179.

The following snippet code provides information about how to retrieve MCC on various J2ME enabled handsets (an expanded example may be found at [1]):

	public String getMCC() {
String out = "";
try {
if (out == null || out.equals("null") || out.equals("")) {
out = System.getProperty("phone.mcc");
}
if (out == null || out.equals("null") || out.equals("")) {
if (out == null || out.equals("null") || out.equals("")) {
out = System.getProperty("com.sonyericsson.net.mcc");
}
}
if (out == null || out.equals("null") || out.equals("")) {
out = getIMSI().equals("") ? "" : getIMSI().substring(0, 3);
}
if (out == null || out.equals("null") || out.equals(""))//getMNC()
{
if (out == null || out.equals("null") || out.equals("")) {
out = System.getProperty("mcc");
}
}
} catch (Exception e) {
return out == null ? "" : out;
}
return out == null ? "" : out;
}
public String getIMSI() {
String out = "";
try {
out = System.getProperty("IMSI");
if (out == null || out.equals("null") || out.equals("")) {
out = System.getProperty("phone.imsi");
}
if (out == null || out.equals("null") || out.equals("")) {
out = System.getProperty("com.nokia.mid.mobinfo.IMSI");
}
if (out == null || out.equals("null") || out.equals("")) {
out = System.getProperty("com.nokia.mid.imsi");
}
if (out == null || out.equals("null") || out.equals("")) {
out = System.getProperty("IMSI");
}
if (out == null || out.equals("null") || out.equals("")) {
out = System.getProperty("imsi");
}
} catch (Exception e) {
return out == null ? "" : out;
}
return out == null ? "" : out;
}

If you are interested in the complete set of system properties for Nokia phones, please check the technical study TSJ000306.

This page was last modified on 11 November 2011, at 03:03.
240 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved