How To - Programmatically read the attributes of a JAD file

Summary

This article applies to the following:

  • BlackBerry® Device Software 4.3 and later
  • BlackBerry smartphone

Details

When publishing an application over the wireless network, the application developer may need to access the contents of the corresponding Java® Application Descriptor (JAD) file to read attributes embedded in the file.

The following is a sample JAD file:

Manifest-Version: 1.0
MIDlet-Version: 1.0.1
MIDlet-Name: My App
MIDlet-Description: My description
MIDlet-Vendor: My Company, Inc.
RIM-COD-Module-Name: Sample JAD
RIM-COD-URL-1: FileOne.cod
RIM-COD-Size-1: 20000
RIM-COD-URL-2: FileTwo.cod
RIM-COD-Size-2: 10000
My-Custom-JAD-Property: Hello There!

In BlackBerry Device Software 4.3 and later, the BlackBerry smartphone introduces support for programmatically reading the contents of the JAD file added or modified after the application has been built. This allows a developer to add dynamic content to a JAD file that could be unique for a particular user or installation.

Custom JAD attributes can be read prior to JAD version 4.3.0. However, the custom JAD file attributes must be added to the JAD file before build time and cannot be modified after the application has been built. To accomplish this the JAD file must be added to the project in the BlackBerry Java® Development Environment (BlackBerry JDE) or BlackBerry® JDE Plug-in for Eclipse™. This means that the custom attribute is identical for all BlackBerry smartphone users who install the application and are using BlackBerry Device software 4.3.0 or earlier.

For a MIDlet, JAD file attributes can be read by calling MIDlet.getAppProperty(). For a Connected Limited Device Configuration (CLDC) application that is leveraging the BlackBerry smartphone application programming interfaces (API), JAD file attributes can be read by callingCodeModuleGroup.getProperty(). Examples for each application type are provided below.

MIDlet example:

String description = MIDlet.getAppProperty("MIDlet-Description");
String custom = MIDlet.getAppProperty("My-Custom-JAD-Property");

BlackBerry smartphone API example:

CodeModuleGroup[] allGroups = CodeModuleGroupManager.loadAll();
CodeModuleGroup myGroup = null;
String moduleName = ApplicationDescriptor
   .currentApplicationDescriptor().getModuleName();

for (int i = 0; i < allGroups.length; i++) {
   if (allGroups[i].containsModule(moduleName)) {
      myGroup = allGroups[i];
      break;
    }
}

// Get the property
String description = myGroup.getProperty("MIDlet-Description");
String custom = myGroup.getProperty("My-Custom-JAD-Property");

For more information on JAD files and publishing applications over the wireless network, see theDeploying Java Applications whitepaper.

Note: Auto-start applications that read JAD file attributes should implement a short delay (approximately 1 second) before attempting to read JAD file attributes on its first startup. When an auto-start application is installed it will start up in parallel to the BlackBerry smartphone saving the JAD file information. This can result in a race condition where the application tries to read the attributes before they have been saved, resulting in a failure to access the attributes. This only occurs the first time an application is installed and the BlackBerry smartphone is not restarted during the installation.

 

Keywords

deploy, OTA, over the air, JAD, property, read, application, descriptor, MIDlet, CLDC, getAppProperty, CodeModuleGroup

你可能感兴趣的:(eclipse,Access,UP,AIR,BlackBerry)