通常一個MIDlet程序有兩個運行時屬性,系統的和程序的(system and application)。這些屬性都只能讀取,不能修改。
系統屬性
系統的屬性一般是由設備定義的。在各個jsr標準中定義了一些系統屬性的鍵值(key)。附1的表格就列出了當前的一些已經定義的系統屬性名。
讀取方法:System.getProperty() ,這是一個靜態方法
程序屬性
程序屬性是在程序的描述文件中和jar包的manifest文件中定義。附2中就就是一個典型的描述文件。假如同樣的屬性在描述文件中和manifest文件中都被定義了,沖突會這樣被處理:假如MIDlet是一個MIDP2.0的可信任的程序,系統會直接拒絕安裝程序。否則,程序描述文件中定義的值會覆蓋manifest中定義的屬性。(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.)
讀取方法:MIDlet.getAppProperty(),這是一個實例方法
注意:1、這些屬性的名稱是區分大小寫的。2、假如獲取一個沒有定義過的名稱,會返回一個null值。3、不要定義太多的屬性,有些設備上的描述大小是有限制的。
原文參看:http://developers.sun.com/techtopics/mobility/midp/ttips/appproperty/index.html
附1:
J2ME Defined System Properties
JSR |
Property Name
|
Default Value1 |
30 |
microedition.platform |
null |
|
microedition.encoding |
ISO8859_1 |
|
microedition.configuration |
CLDC-1.0 |
|
microedition.profiles |
null |
37 |
microedition.locale |
null |
|
microedition.profiles |
MIDP-1.0 |
75 |
microedition.io.file.FileConnection.version |
1.0 |
|
file.separator |
(impl-dep) |
|
microedition.pim.version |
1.0 |
118 |
microedition.locale |
null |
|
microedition.profiles |
MIDP-2.0 |
|
microedition.commports |
(impl-dep) |
|
microedition.hostname |
(impl-dep) |
120 |
wireless.messaging.sms.smsc |
(impl-dep) |
139 |
microedition.platform |
(impl-dep) |
|
microedition.encoding |
ISO8859-1 |
|
microedition.configuration |
CLDC-1.1 |
|
microedition.profiles |
(impl-dep) |
177 |
microedition.smartcardslots |
(impl-dep) |
179 |
microedition.location.version |
1.0 |
180 |
microedition.sip.version |
1.0 |
184 |
microedition.m3g.version |
1.0 |
185 |
microedition.jtwi.version |
1.0 |
195 |
microedition.locale |
(impl-dep) |
|
microedition.profiles |
IMP-1.0 |
205 |
wireless.messaging.sms.smsc |
(impl-dep) |
205 |
wireless.messaging.mms.mmsc |
(impl-dep) |
211 |
CHAPI-Version |
1.0 |
附2
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