OTA on BlackBerry - How to Detect OS Version From the Browser User Agent

I do an OTA (over the air) distribution for BlackBerry. Some time ago, I wrote here how to [link id='206' text='setup the mime types for the OTA distribution on Amazon S3']. Luckily now, S3 has got a new and very useful web interface, as well as improved mime type detection. They still get the file types not exactly right, but close enough so that the OTA installation for BlackBerry works on "autodetect" settings just fine.

This is however not about S3, this is about detecting the proper OS version of the BlackBerry OS from the user agent of the browser using a few very simple regular expressions.  The code is tailored to PHP, but you can easily adapt it to any language that supports Perl style regular expressions, or you can adapt the reg. expressions as well based on this simple idea:


       $agent = //get user agent raw string

        if (preg_match("/BlackBerry/i", $agent)) {

            if (preg_match("/6\.0\../i", $agent)) {
                $newRelease['os_folder'] = "6.0";
            }
            if (preg_match("/5\.0\../i", $agent)) {
                $newRelease['os_folder'] = "5.0";
            }
            if (preg_match("/4\.7\../i", $agent)) {
                $newRelease['os_folder'] = "4.7";
            }
            if (preg_match("/4\.6\../i", $agent)) {
                $newRelease['os_folder'] = "4.6";
            }
            if (preg_match("/4\.5\../i", $agent)) {
                $newRelease['os_folder'] = "4.5";
            }
            if (preg_match("/4\.3\../i", $agent)) {
                $newRelease['os_folder'] = "4.3";
            }
            if (preg_match("/4\.2\.1/i", $agent)) {
                $newRelease['os_folder'] = "4.2.1";
            }

            //Form your download URL here

        } else {
            //This is not BlackBerry user agent
        }

Nothing complicated, but this should give a start point to any one tying to serve appropriate bundle via OTA.

 

If you were to use S3, then it would basically be:


// The main link to S3
$downloadURL = "https://s3.amazonaws.com/YOUR_BUCKET/releases/" . $newRelease['version_folder'] . "/" . $newRelease['os_folder'] . "/YourAppName.jad";

Post your thoughts/corrections in the comments!