Sun Java Solaris Communities My SDN Account Join SDN
 
Article

MIDP Application Properties

 
By Eric Giguere, April 11, 2005  
A MIDlet, an application based on the Mobile Information Device Profile (MIDP), has access to two sets of runtime properties: system and application.
 
The concept of system properties is actually defined by the Connected Limited Device Configuration (CLDC), on which the MIDP is based. The underlying platform sets the properties and the application can obtain their values but cannot change them. The set of system properties varies depending on what features are available on the platform - see the FAQ "What are the defined J2ME system property names?" for a partial list of common system properties. To read a system property the MIDlet invokes System.getProperty(), a static method.
 
Application properties are obtained from the union of the attributes defined in the application descriptor and those in the MIDlet suite's manifest, part of the JAR file packaging. You set their values when you package the application for deployment. Consider a typical application descriptor:
 
	MIDlet-1: HttpWrapperMidlet,,httpwrapper.HttpWrapperMIDlet
	MIDlet-Jar-Size: 16315
	MIDlet-Jar-URL: HttpWrapper.jar
	MIDlet-Name: HttpWrapper
	MIDlet-Vendor: Vendor
	MIDlet-Version: 1.0
	MicroEdition-Configuration: CLDC-1.0
	MicroEdition-Profile: MIDP-1.0
	Which-Locale: en

To read an application property like the Which-Locale attribute in this descriptor, a MIDlet invokes MIDlet.getAppProperty(), a non-static, instance method. This example code obtains the name of the MIDlet suite by querying the MIDlet-Name property:
 
	import javax.microedition.midlet.*;

	public class MyMIDlet extends MIDlet {
		private String suiteName;

		public MyMIDlet(){
			suiteName = getAppProperty( "MIDlet-Name" );
			... // more stuff
		}

		... // etc.
	}

Property names are case-sensitive. If a property is not defined by either the application descriptor or the manifest, null is returned. If the same property is defined differently in the application descriptor and the manifest, the conflict is resolved in one of two ways: If the MIDlet is a trusted application based on MIDP 2.0, the system simply won't install the application. Otherwise, the value in the descriptor overrides the value in the manifest.
 
Application properties are particularly useful when descriptors are generated dynamically. For example, you can embed a registration key in the descriptor that the application will read and pass back to a registration server the first time it's run, without having to recompile or repackage the application itself. Don't stuff a lot of data in the descriptor, though, because some platforms limit the descriptor size. Use application properties wherever you'd use a standard Java properties file in a J2SE application.
 
About the Author: Eric Giguere is a software developer for iAnywhere Solutions, a subsidiary of Sybase, where he works on Java technologies for handheld and wireless computing. He holds BMath and MMath degrees in Computer Science from the University of Waterloo and has written extensively on computing topics.
Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.