The <deviceRequirements> Section
Select your target devices in the <deviceRequirements> section!
Select the devices that you want to target in the <deviceRequirements> section. You will typically target one generic device
such as the
Generic/AnyMsaPhone along with some platform specific target phones like
<deviceRequirements if="test"> <requirement name="Identifier" value="Generic/AnyMsaPhone" /> </deviceRequirements> <deviceRequirements unless="test"> <requirement name="Identifier" value="Generic/AnyMsaPhone,Nokia/Series60E3,BlackBerry/7.1,Generic/android2.3,Generic/android4.0" /> </deviceRequirements>
You can use any device capabilities for choosing your target devices:
<deviceRequirements if="test"> <requirement name="Identifier" value="Generic/AnyMsaPhone" /> </deviceRequirements> <deviceRequirements unless="test"> <requirement name="Term" value="polish.api.mmapi and (polish.midp2 or polish.midp3)" /> </deviceRequirements>
In this example two alternative device-selections are defined - when the test-property is
set to true (by defining it with
<property name="test" value="true" />),
only the upper
<deviceRequirements> element is used and the second
<deviceRequirements> element is ignored. The actual requirements are defined
with the sub elements
<requirement>. Without any clarification, all listed
requirements need to be fulfilled by the device to be selected.
<xor> elements, which can be used to
define the requirements very flexible.
Following attributes are supported by the device-requirements section:
|if||No||The name of the Ant-property which needs to be "true" or "yes" to use this <deviceRequirements>.|
|unless||No||The name of the Ant-property which needs to be "false" or "no" to use this <deviceRequirements>.|
Following nested elements can be used in a <deviceRequirements> element:
|requirement||Yes||The requirement which needs to be fulfilled by the device.|
|and||No||Series of requirements, of which all need to be fulfilled.|
|or||No||Series of requirements, of which at least one needs to be fulfilled.|
|xor||No||Series of requirements, of which one needs to be fulfilled.|
|not||No||Series of requirements, of which none must be fulfilled.|
The actual work is done by the <requirement> element:
|name||Yes||The name of the needed capability, e.g.
|value||Yes||The needed value of the capability, e.g.
|type||No||The class which controls this requirement. Either a class which extends the
The <or>, <and>, <not> and <xor> elements can be nested in any manner:
<deviceRequirements> <requirement name="BitsPerPixel" value="4+" /> <or> <requirement name="JavaPackage" value="nokia-ui, mmapi" /> <and> <requirement name="JavaPackage" value="mmapi" /> <requirement name="JavaPlatform" value="MIDP/2.0+" /> </and> </or> </deviceRequirements>
In this example each supported device must have a color depth of at least 4 bits per pixel. Additionally the device needs to support either the Nokia-UI-API and the Mobile Media-API (mmapi), or the Mobile Media-API and the MIDP/2.0 platform.
Instead of using such nested requirements, you can also use the "Term" requirement that allows you to select devices with the same power like the #if preprocessing directive. The following example includes the very same requirements like the above one - but only one "Term" requirement is used:
<deviceRequirements> <requirement name="Term" value="(polish.BitsPerPixel >= 4) and ((polish.api.nokia-ui and polish.api.mmapi) or (polish.api.mmapi and polish.midp2))" /> </deviceRequirements>
J2ME Polish provides several requirements that can be used "out of the box":
|BitsPerPixel||Needed color depth of the device: 1 is monochrome,
4 are 16 colors,
8 = 256 colors,
16 = 65.536 colors,
24 = 16.777.216 colors.
|ScreenSize||Required width and height of the display, e.g. "120+ x 100+" for a resolution of at least 120 pixels horizontally and 100 pixels vertically.
|ScreenWidth||The needed horizontal resolution of the display , e.g. "120+" for at least 120 pixels.
|ScreenHeight||The needed vertical resolution of the display, e.g. "100+" for at least 100 pixels.
|CanvasSize||Required width and height of the MIDP-Canvas. Some devices do not allow the usage of the complete screen.
|JavaPlatform||The needed platform, e.g. "MIDP/1.0" or "MIDP/2.0+".
|JavaConfiguration||The needed platfconfiguration, e.g. "CLDC/1.1+".
|JavaPackage||Needed APIs, e.g. "nokia-ui, mmapi":
|JavaProtocol||Needed data exchange protocols, e.g. "serial, socket":
|HeapSize||The needed heap size of the device, e.g. "200+ kb" or "1.1+ MB"
|Vendor||The vendor of the device, e.g. "Nokia" or "Siemens".
|Identifier||The identifier of the device, e.g. "Nokia/N95 ".
|Feature||A feature which needs to be supported by the device.
|Term||A preprocessing term that needs to be fulfilled by the device. You can use this flexible requirement just like the //#if-preprocessing directive in your source code.