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');
}
}
No comments:
Post a Comment