Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Determine the country code of the current mobile subscriber

by Retired ‎02-12-2010 03:22 PM - edited ‎02-17-2010 09:46 AM (5,134 Views)


This article applies to the following:

  • BlackBerry® Device Software 4.0 and later
  • BlackBerry smartphones based on Java® technology


Each BlackBerry smartphone that is active on a wireless network has a unique identifier known as the International Mobile Subscriber Identity (IMSI). On GSM® networks, the IMSI is associated with the Subscriber Identity Module (SIM) card. On Code Division Multiple Access (CDMA) networks, the IMSI is assigned to the BlackBerry smartphone.

An application may benefit from knowing the country associated with the IMSI. For example, an application might launch different URLs in the BlackBerry® Browser, depending on the country in which the wireless service account is based.

The following sample code demonstrates how to retrieve the IMSI of the BlackBerry smartphone and how to determine the Mobile Country Code (MCC) that is embedded in the IMSI:

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;

* This class determines the country code associated with the current subscriber's wireless carrier.
class CountryFromIMSI {

// MCC examples
public static final int MCC_FOR_USA = 784; // MCC for USA is 310 (hex)
public static final int MCC_FOR_CANADA = 770; // MCC for Canada is 302 (hex)

/** Returns the country code associated with the current mobile subscriber's wireless carrier. */
public static int getCountryCodeForCurrentSubscriber() {

byte [] imsi = getIMSI();

return getMCCFromIMSI(imsi);

private static int getMCCFromIMSI( byte [] imsi ) {
if( imsi == null || imsi.length < 3 ) {
return -1;

// the first three bytes of the IMSI string represents the country code
int mcc = 0;
for( int i = 0; i < 3; ++i ) {
mcc *= 10;
mcc += imsi[i];

String mccString = "" + mcc;
int mccAsDecimal = Integer.parseInt(mccString, 16);

return mccAsDecimal;

private static byte [] getIMSI() {
try {

if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA) {

return CDMAInfo.getIMSI();

} else {

return SIMCardInfo.getIMSI();

} catch (Exception e) {
return null;

Determining the MNC from the IMSI

In addition to the MCC, you can also extract the Mobile Network Code (MNC) from the IMSI.

The MNC is represented by the three digits following the three leading MCC digits. The MNC can be determined with code similar to that given in the example above.

Users Online
Currently online: 13 members 1,185 guests
Please welcome our newest community members: