Detailed explanation of properties in MIDP

zhaozj2021-02-16  82

This paper is to illustrate the properties issues in MIDP, mainly involving some concepts of JAD and Manifest.mf files. In fact, many people don't know the details of this. So you should read this article carefully.

Usually the MIDP application is published in .jar files and .jad files. JAR file is the JAR package we said, the full name of JAD file is Java Application Descriptor. In the JAD file contains information on the life cycle of the application management software to manage MIDlets, of course, there are also many important properties. They are pairs, for example: MIDlet-name: myjava. You can get the String type Myjava by calling getAppproperty ("MIDlet-name"), which is very convenient, if you want your MIDlet to network, then you can define a name for server_url, define its value as http : // Yourip: Port / MyServlet, so if you want to connect to other addresses, you only need to modify the JAD file, do not need to recompile. So we must know that the value that is placed in the JAD file in the JAD file is more preferred.

In the JAR package, it includes a directory Meta-Info with a file is manifest.mf. It is used to describe the JAR file, and some other information, you may find that in the manifest.mf and some values ​​in the JAD file are the same. Then there is a rule, how is AMS decided to read which value? The answer is this.

If MIDLETS's JAR package is signed, then AMS wants to look at its digital signature. If it is valid, it will first read the contents of manifest.mf, then read the same content in the JAD file, if you match, then It will install this JAR package, and if you don't match, you will refuse to install. If he discovers that the digital signature is invalid, it will refuse to install. If the MDileTs's JAR package is unsigned, then AMS thinks it is not trustworthy. He read the properties of the JAD file. If you find that it is not, it reads the content of manifest, that is, if there is JAD and Manifest The properties AMS will only read the JAD.

The following logic looks more clearly: Given: String Key // Attribute Name Return: String Value Throws: NullPointersException if Key Is NULL

IF trusted string v0 = lookup key in manifest string v1 = lookup key in Descriptor

IF (v0! = null && v1! = null) // Found in Both; Must Be The Same Value Assert (v0.comPareto (V1) == 0);

Value = (v1! = null)? V1: v0; else // untrusted value = Lookup key in Descriptor

IF value == null value = lookup key in manifest

Return Value

The following briefly introduces some important parameters defined in MIDP 2.0, and 18 values ​​are defined in MIDP 2.0. There must be six in manifest.mf and jad, they are: midlet-name midlet-version midlet-vendor microedition-profile microedition-configuration midlet-n Since there can be multiple MIDlets in a MIDlet Suite, therefore You have to explain that they are like midlet-1, midlet-2 ..... MIDlet-n, this is very important, be sure to make sure that the MIDlet-name is correct when deploying JAR and JAD files to the phone, its value is Your name of your JAR package! Otherwise it will not be installed. There are two values ​​that are not available in the manifest file. They are midlet-jar-url, and MIDlet-jar-size should be noted that the midlet-jar-url, if you download by OTA, then you don't let him point to Your JAR package absolute address, such as http: // myip: port / app / myapp.jar. I wrote a simple code test with a simple code. If you still have questions, you can run the following program: import javax.microedition.lcdui.display; import javax.microedition.lcdui .Form; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; / * * Created on 2004-7-14 * * TODO to change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates * /

/ ** * @Author E2412C * * Todo to change Ty test go to * window - preferences - java - code style - code templates * / public class midlet1 extends MIDlet {

private Display display; / * (non-Javadoc) * @see javax.microedition.midlet.MIDlet # startApp () * / protected void startApp () throws MIDletStateChangeException {// TODO Auto-generated method stub display = Display.getDisplay (this DISPLAY.SETCURRENT (New Form ("1"));

/ * (non-javadoc) * @see javax.microedition.midlet.midlet # Pauseapp () * / protected void Pauseapp () {// Todo auto-generated method stub

}

/ * (Non-Javadoc) * @see javax.microedition.midlet.MIDlet # destroyApp (boolean) * / protected void destroyApp (boolean arg0) throws MIDletStateChangeException {// TODO Auto-generated method stub}

} Import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; / * * Created on 2004-7-14 * * TODO To change the template for this generated file go to * window - preferences - java - code style - code templates * /

/ ** * @Author E2412C * * Todo to change Ty test go to * window - preferences - java - code style - code templates * / public class midlet2 extends midlet {

private Display display; / * (non-Javadoc) * @see javax.microedition.midlet.MIDlet # startApp () * / protected void startApp () throws MIDletStateChangeException {// TODO Auto-generated method stub display = Display.getDisplay (this ); Display.setcurrent (New form ("2"));

/ * (non-javadoc) * @see javax.microedition.midlet.midlet # Pauseapp () * / protected void Pauseapp () {// Todo auto-generated method stub

}

/ * (Non-Javadoc) * @see javax.microedition.midlet.MIDlet # destroyApp (boolean) * / protected void destroyApp (boolean arg0) throws MIDletStateChangeException {// TODO Auto-generated method stub

}

} Import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; / * * Created on 2004-7-14 * * TODO to change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates * // ** * @author E2412C * * TODO to change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * / Public Class Midlet3 Extends MIDlet {

private Display display; / * (non-Javadoc) * @see javax.microedition.midlet.MIDlet # startApp () * / protected void startApp () throws MIDletStateChangeException {// TODO Auto-generated method stub display = Display.getDisplay (this DISPLAY.SETCURRENT (New Form ("3");}

/ * (non-javadoc) * @see javax.microedition.midlet.midlet # Pauseapp () * / protected void Pauseapp () {// Todo auto-generated method stub

}

/ * (Non-Javadoc) * @see javax.microedition.midlet.MIDlet # destroyApp (boolean) * / protected void destroyApp (boolean arg0) throws MIDletStateChangeException {// TODO Auto-generated method stub

}

} The JAD file is as follows: MIDlet-3: MIDlet3, MIDLET3MIDLET-2: MIDlet1, MIDlet1MIDLET-1: MIDLET2, MIDLET2MIDLET-JAR-URL: MIDLETS.jarmicroedition-Configuration: CLDC-1.0MIDlet-Version: 1.0.0midlet -Name: MIDletsmidlet-vendor: MIDlet Suite VendormicRoEdition-Profile: MIDP-1.0 Pack the above three.java files into a MIDlets.jar file, and then double-click .jad file. The program can run, I don't have any problems in WTK2.1!

转载请注明原文地址:https://www.9cbs.com/read-15855.html

New Post(0)