Welcome!

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

Format the electronic serial number (ESN)

by BlackBerry Development Advisor ‎02-16-2010 11:17 AM - edited ‎09-16-2010 02:35 PM (1,496 Views)

Summary

 

This article applies to the following:

  • BlackBerry® Java® Development Environment (BlackBerry JDE)
  • BlackBerry smartphones based on Java technology

Details

 

The following code can be used to format the ESN of a BlackBerry smartphone to match the format that is shown under Options > Status on the BlackBerry smartphone.

 

Note: ESNs are only present on BlackBerry smartphones that operate on the Code Division Multiple Access (CDMA) network.

 

 

public String getDecimalSerialNumber()
{
StringBuffer esnStringBuffer = new StringBuffer();

//Determine if the BlackBerry operates on the CDMA network.
if( RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA )
{
//It does, so we'll format the ESN number.
int sn = CDMAInfo.getESN();
int firstPart = (sn >> 24) & 0xff;
int secondPart = sn & 0xffffff;

String firstPartString = String.valueOf( firstPart );
String secondPartString = String.valueOf( secondPart );
padESN( esnStringBuffer, 3 - firstPartString.length() );
esnStringBuffer.append( firstPartString );
padESN( esnStringBuffer, 8 - secondPartString.length() );
esnStringBuffer.append( secondPartString );

return esnStringBuffer.toString();
}
else
{
//This BlackBerry does not operate on the CDMA network,
//return 0.
esnStringBuffer.append(0);
}

return esnStringBuffer.toString();
}

//Inserts zeros into the ESN string.
private void padESN(StringBuffer esnStringBuffer, int padCount)
{
for (int i = 0; i < padCount; ++i) {
esnStringBuffer.append('0');
}
}

 

 

 

Contributors