|
How do I find the BlackBerry OS version? |
|
The user of a BlackBerry wireless handheld can find the operating system (OS) version by selecting Applications from the Options application. You'll end up with a screen like this:
In this example, the device is running version 3.7 of the operating system. Programmatically, the easiest way to get the version number is to obtain the version string for the net_rim_bb_browser_daemon module: import net.rim.device.api.system.CodeModuleManager;
int handle = CodeModuleManager.getModuleHandle( "net_rim_bb_browser_daemon" );
if( handle != 0 ){
String version = CodeModuleManager.getModuleVersion( handle );
}
The version string will be in the "A.B.C.D" format, for example "3.7.0.58". Looking for a specific version is just a matter of using the startsWith method: public String is37( String version ){
return version.startsWith( "3.7." );
}
A more comprehensive approach is convert each part of the string into an integer: /**
* Returns the version information as an int array, with
* index 0 being the leftmost version number (the major
* OS version) and index 3 being the rightmost version number
* (the build number). For example:
* <pre>
* int[] version = getVersion();
* if( ( version[0] == 3 && version[1] >= 8 ) ||
* version[0] >= 4 ){
* // this is version 3.8 or higher
* }
* </pre>
*/
public int[] getVersion(){
int[] ret = new int[4]{ 3, 6, 0, 0 }; // def to 3.6
int h = CodeModuleManager.getModuleHandle( "net_rim_bb_browser_daemon" );
if( h == 0 ) return ret;
String v = CodeModuleManager.getModuleVersion( h );
int p1 = v.indexOf( '.' );
int p2 = v.indexOf( '.', p1+1 );
int p3 = v.indexOf( '.', p2+2 );
try {
ret[0] = Integer.parseInt( v.substring( 0, p1 ) );
ret[1] = Integer.parseInt( v.substring( p1+1, p2 ) );
ret[2] = Integer.parseInt( v.substring( p2+1, p3 ) );
ret[3] = Integer.parseInt( v.substring( p3+1 ) );
}
catch( NumberFormatException e ){
// ignore it
}
return ret;
}
Note that the BlackBerry platform number is different than the OS version, so DeviceInfo.getOSVersion() returns a different number than the code shown above. |
Please respect our copyrights and ask for permission before using any of the material you see here.
Sitemaps: HTML | XML | Text