J2ME 應用常需查詢設備能力(如支持的 API 版本、硬件特性、本地化信息)以實現動態適配。平台通過 System.getProperty(String key) 提供標準化屬性訪問接口,本文彙總核心屬性表供開發查閱。
| 屬性鍵 | 返回值示例 | 說明 |
|---|---|---|
| microedition.profiles | MIDP-2.0 | 支持的 MIDP 版本 |
| microedition.configuration | CLDC-1.1 | 支持的 CLDC 版本 |
| microedition.locale | zh-CN | 設備語言/地區 |
| microedition.platform | NokiaN73/5.0 | 設備品牌型號 |
| microedition.encoding | UTF-8 | 默認字符集 |
| microedition.commports | comm:com0,comm:com1 | 可用串口列表 |
| microedition.hostname | device.local | 本地主機名(MIDP 2.0) |
| microedition.jtwi.version | 1.0 | JTWI 規範版本 |
若返回 null 表示不支持該 JSR:
| 屬性鍵 | 對應 JSR / API |
|---|---|
| microedition.media.version | MMAPI (JSR 135) |
| microedition.pim.version | PIM API (JSR 75) |
| microedition.m3g.version | M3G 3D 圖形 (JSR 184) |
| microedition.location.version | Location API (JSR 179) |
| bluetooth.api.version | Bluetooth API (JSR 82) |
| microedition.io.file.FileConnection.version | FileConnection (JSR 75) |
| microedition.global.version | 國際化 API (JSR 238) |
| microedition.chapi.version | Content Handler (JSR 211) |
| microedition.sip.version | SIP API (JSR 180) |
| 屬性鍵 | 返回值 | 含義 |
|---|---|---|
| supports.mixing | true/false | 是否支持多音頻混音 |
| supports.audio.capture | true/false | 支持錄音 |
| supports.video.capture | true/false | 支持錄像 |
| audio.encodings | encoding=audio/wav encoding=audio/amr | 支持音頻編碼格式 |
| video.encodings | encoding=video/3gpp encoding=video/mp4 | 支持視頻編碼格式 |
| video.snapshot.encodings | encoding=png encoding=jpeg | 視頻幀截圖格式 |
| streamable.contents | audio/mpeg video/3gpp | 流媒體支持格式 |
| 屬性鍵 | 典型值示例 | 說明 |
|---|---|---|
| fileconn.dir.photos | file:///c:/My Files/Images/ | 圖片存儲目錄 |
| fileconn.dir.videos | file:///c:/My Files/Videos/ | 視頻存儲目錄 |
| fileconn.dir.tones | file:///c:/My Files/Tones/ | 鈴聲存儲目錄 |
| fileconn.dir.memorycard | file:///d:/ | 存儲卡根目錄 |
| fileconn.dir.private | file:///c:/System/MIDlets/[suiteID]/ | MIDlet 私有目錄 (S40 不支持) |
| file.separator | / | 路徑分隔符 |
// 獲取設備型號
String model = System.getProperty("microedition.platform");
// 檢測是否支持文件操作
String fcVer = System.getProperty("microedition.io.file.FileConnection.version");
boolean hasFileAPI = (fcVer != null);
// 獲取支持的音頻格式
String audioEnc = System.getProperty("audio.encodings");
區分系統屬性與應用屬性: JAD 清單中定義的屬性(如 MIDlet-Version)需通過 MIDlet.getAppProperty() 讀取,而非 System.getProperty()。
善用屬性檢測實現「編寫一次,動態適配」,是 J2ME 碎片化環境下保證應用兼容性的核心技能。