Sven
Sven

Reputation: 6338

Packaging Blackberry App for different OS Versions with a JAD File

What I am looking for:

I want to package my Application for different blackberry os versions (5,6 and 7). So that the user doesn't have to know what version he needs and just installs the app from the website.

What I have already found out:

What I think is my problem:

I do not know how to package those three directories in the web directory. I think I need just one folder and a JAD file that somehow manages what version of my app is being installed?

Can you please give me some insights.

Upvotes: 2

Views: 1540

Answers (1)

donturner
donturner

Reputation: 19146

If your app only uses the OS5 API

If you develop your app using the OS5 BlackBerry JRE (Java Runtime Environment) then it will run on all devices running OS5, 6 and 7. The BlackBerry OS is backward compatible with previous OSs, so you don't have to worry about packaging for individual OS versions.

As far as packaging the app up, you just need to upload the appname.jad and appname.cod files in deliverables/Standard/5.0.0 to your web server, then direct your users to it from their BB phone, they should be prompted to download and install it.

If your app uses multiple APIs

You will need to distribute a cod and jad file for each API version you are using. Upload these to your web server then use a script to detect the user's OS version. Here's a PHP script to do this:

<?php 

$strUserAgent = $_SERVER['HTTP_USER_AGENT'];

if (strpos($strUserAgent, "BlackBerry") !== FALSE){

$blnOSFound = false;

echo "This is a BlackBerry.";

/**
 * BlackBerrys have 2 user agent string formats, check for both:
 *
 * Mozilla/5.0 (BlackBerry; U; BlackBerry 9860; en-GB) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.296 Mobile Safari/534.11+
 * BlackBerry9700/5.0.0.351 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/123
 *
 */
$arrAgentParts = explode(" ", $strUserAgent);

for ($i=0;$i<count($arrAgentParts);$i++){

    $strAgentPart = $arrAgentParts[$i];
     if (strpos($strAgentPart, "BlackBerry") === 0 &&
        strpos($strAgentPart, "/") !== FALSE){

        $intPositionOfSlash = strpos($strAgentPart, "/"); 
        $strOSVersion = substr($strAgentPart, $intPositionOfSlash+1, strlen($strAgentPart));
        $blnOSFound = true;
        break;

    } else if (strpos($strAgentPart, "Version") === 0){
        $intPositionOfSlash = strpos($strAgentPart, "/"); 
        $strOSVersion = substr($strAgentPart, $intPositionOfSlash+1, strlen($strAgentPart));
        $blnOSFound = true;
        break;            
    }
}

if ($blnOSFound){
    echo " OS Version: ".$strOSVersion;

    $intMajorOSVersion = substr($strOSVersion, 0, 1);

    //Redirect user to the jad file for their OS version
    switch ($intMajorOSVersion){

    case 5:
        Header("Location: 5.0.0/myapp.jad");
        break;  
    case 6:
        Header("Location: 6.0.0/myapp.jad");
        break;
    case 7:
        Header("Location: 7.0.0/myapp.jad");
        break;
    default:
        echo "Unsupported OS version";
        break;
    }

} else {
    echo " Could not find OS version";
}

} else {
echo "Not a BlackBerry";
}

?>

You might want to hack around with this a bit to remove the echo statements.

When developing your app for multiple APIs there are 2 approaches:

  1. Maintain separate projects for each API version and use a common library of code which will run on all APIs to avoid duplicate code
  2. Define preprocessor directives in your BlackBerry_App_Descriptor.xml to conditionally include code based on the target OS. You will need to change the referenced BlackBerry JRE each time you change target OS (In Eclipse: Properties->Java Build Path->Libraries).

Upvotes: 4

Related Questions