在J2ME開(kāi)發(fā)中,我們經(jīng)常需要和手機(jī)系統(tǒng)進(jìn)行交互,獲得一些和系統(tǒng)相關(guān)的信息,在J2ME API設(shè)計(jì)中,提供了一系列的系統(tǒng)屬性
表1 CLDC、MIDP和JTWI屬性
屬性名稱(chēng)
|
屬性作用
|
microedition.profiles
|
代表手機(jī)支持的MIDP版本,返回格式值為“MIDP-1.0”或“MIDP-2.0”
|
microedition.configuration
|
代表手機(jī)支持的CLDC版本,返回格式值為“CLDC-1.0”或“CLDC-2.0”
|
microedition.locale
|
代表手機(jī)所在的國(guó)家或地區(qū),返回值格式為“en-US”
|
microedition.platform
|
代表手機(jī)的品牌和型號(hào),Nokia手機(jī)的返回值格式為“Nokia6310i/4.42”
|
microedition.encoding
|
代表手機(jī)默認(rèn)的字符集名稱(chēng),返回值格式為“ISO-8859-1”
|
microedition.commports
|
代表手機(jī)可以使用的串口列表,返回值中各個(gè)串口之間使用逗號(hào)分隔
|
microedition.hostname
|
MIDP2.0定義,代表本地主機(jī)名稱(chēng),需要手機(jī)支持。
|
microedition.jtwi.version
|
代表手機(jī)支持的JTWI版本,值必須是“1.0”
|
表2 可選包屬性
屬性名稱(chēng)
|
屬性作用
|
microedition.media.version
|
代表手機(jī)支持的MMAPI版本,如果不支持則返回null
|
microedition.pim.version
|
代表手機(jī)支持的PIM API版本,如果不支持則返回null
|
microedition.m3g.version
|
代表手機(jī)支持的M3G API版本,如果不支持則返回null
|
microedition.location.version
|
代表手機(jī)支持的Location API版本,如果不支持則返回null
|
Bluetooth.api.version
|
代表手機(jī)支持的BT API版本,如果不支持則返回null
|
microedition.io.file.
FileConnection.version
|
代表手機(jī)支持的FC API版本,如果不支持則返回null
|
microedition.global.version
|
代表手機(jī)支持的Mobile Internationalization API(JSR-238)版本,如果不支持則返回null
|
microedition.chapi.version
|
代表手機(jī)支持的CH(Content Handler) API(JSR211)版本,如果不支持則返回null
|
microedition.sip.version
|
代表手機(jī)支持的SIP API版本,如果不支持則返回null
|
表3 MMAPI屬性
屬性名稱(chēng)
|
屬性作用
|
supports.mixing
|
代表手機(jī)是否支持混音(同時(shí)播放多個(gè)Player),返回值為“true”或“false”
|
supports.audio.capture
|
代表手機(jī)是否支持聲音捕獲(錄音),返回值為“true”或“false”
|
supports.video.capture
|
代表手機(jī)是否支持視頻捕獲(錄像),返回值為“true”或“false”
|
supports.recording
|
代表手機(jī)是否支持記錄(record),返回值為“true”或“false”
|
audio.encodings
|
代表手機(jī)支持的聲音格式,返回值格式為“encoding=audio/wav”,多個(gè)格式之間使用至少一個(gè)空格進(jìn)行間隔
|
video.encodings
|
代表手機(jī)支持的視頻格式,返回值格式為“encoding=video/3gpp”,多個(gè)格式之間使用至少一個(gè)空格進(jìn)行間隔
|
video.snapshot.encodings
|
代表手機(jī)使用getSnapshot方法獲得的視頻快照格式,返回值格式為“encoding=png”,多個(gè)格式之間使用至少一個(gè)空格進(jìn)行間隔
|
streamable.contents
|
代表手機(jī)支持的流媒體格式,返回null代表不支持
|
表4 Wireless Messaging API屬性
屬性名稱(chēng)
|
屬性作用
|
|
代表手機(jī)發(fā)送短信時(shí)的短信服務(wù)中心號(hào)碼
|
表5 FileConnection API
屬性名稱(chēng)
|
屬性作用
|
fileconn.dir.photos
|
代表手機(jī)中存儲(chǔ)照片和其它圖片的目錄,例如“file:///c:/My files/ Images /”
|
fileconn.dir.videos
|
代表手機(jī)中存儲(chǔ)視頻的目錄,例如“file:///c:/My files/Video clips/”
|
fileconn.dir.tones
|
代表手機(jī)中存儲(chǔ)聲音的目錄,例如“file:///c:/My files/Tones/”
|
fileconn.dir.memorycard
|
代表手機(jī)中存儲(chǔ)卡的根目錄。例如“file:///d:/”
|
fileconn.dir.private (Nokia S40不支持)
|
代表手機(jī)中MIDlet的私有工作目錄,例如“file:///c:/System/MIDlets/[1015f294]/scratch”
|
fileconn.dir.photos.name
|
代表手機(jī)中圖片目錄的名稱(chēng),例如“Images”
|
fileconn.dir.videos.name
|
代表手機(jī)中視頻目錄的名稱(chēng),例如“Video clips”
|
fileconn.dir.tones.name
|
代表手機(jī)中聲音目錄的名稱(chēng),例如“Sound clips”
|
file.separator
|
代表手機(jī)中的文件分隔符,例如“/”
|
fileconn.dir.memorycard.name
|
代表手機(jī)中存儲(chǔ)卡的名稱(chēng),例如“Memory card”
|
使用這些屬性,可以獲得在程序運(yùn)行過(guò)程中需要的很多和系統(tǒng)相關(guān)的信息,也可以使用表2中的屬性來(lái)獲得手機(jī)是否支持對(duì)應(yīng)的可選包等信息。
實(shí)際使用示例:String name = System.getProperty(“microedition.platform”);
注意:如果需要獲得JVM或jad文件中的信息,需要使用MIDlet類(lèi)中的getAppProperty方法,其屬性名則需要查閱jad文件的設(shè)定,和本文所述的屬性名無(wú)關(guān)。