背景與挑戰
IMEI (國際行動裝置識別碼) 與 Cell ID (基站識別碼) 屬於廠商私有擴展,無統一標準 API。各廠商透過 System.getProperty() 以不同鍵名暴露,需針對不同品牌/平台分別處理。
核心實作程式碼 (含 J2ME Polish 預處理指令)
package study;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import de.enough.polish.ui.Form;
public class GetIMEIAndCellId extends MIDlet implements CommandListener {
private Command exitCommand = new Command("exit", Command.EXIT, 1);
private Form form = new Form("imei and cellid");
private Display display;
public GetIMEIAndCellId() {
display = Display.getDisplay(this);
}
protected void destroyApp(boolean unconditional) {}
protected void pauseApp() {}
protected void startApp() throws MIDletStateChangeException {
String info = System.getProperty("microedition.platform");
String imei = "";
String cellid = "";
String lac = "";
// === Sony Ericsson ===
//#if polish.vendor==Sony-Ericsson
imei = System.getProperty("com.sonyericsson.imei");
cellid = System.getProperty("com.sonyericsson.net.cellid");
lac = System.getProperty("com.sonyericsson.net.lac");
//#endif
// === Nokia ===
//#else if polish.vendor==Nokia
imei = System.getProperty("phone.imei");
if (imei == null || imei.equals(""))
imei = System.getProperty("com.nokia.IMEI");
if (imei == null || imei.equals(""))
imei = System.getProperty("com.nokia.mid.imei");
//#if polish.group==Series60
cellid = System.getProperty("com.nokia.mid.cellid");
//#else if polish.group==Series40
cellid = System.getProperty("Cell-ID");
//#endif
//#endif
// === Siemens ===
//#else if polish.vendor==Siemens
imei = System.getProperty("com.siemens.imei");
//#endif
// === Motorola ===
//#else if polish.vendor==Motorola
imei = System.getProperty("com.motorola.IMEI");
cellid = System.getProperty("CellID");
//#endif
// === Samsung ===
//#else if polish.vendor==Samsung
imei = System.getProperty("com.samsung.imei");
//#endif
// 通用後備
if (imei == null || imei.equals(""))
imei = System.getProperty("IMEI");
// 顯示結果
form.append("platform info: " + info);
form.append("imei: " + imei);
form.append("cellid: " + cellid);
form.setCommandListener(this);
form.addCommand(exitCommand);
display.setCurrent(form);
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
廠商屬性鍵名速查表
| 廠商/平台 | IMEI 鍵名 | Cell ID 鍵名 | LAC 鍵名 |
| Sony Ericsson | com.sonyericsson.imei | com.sonyericsson.net.cellid | com.sonyericsson.net.lac |
| Nokia (通用) | phone.imei | — | — |
| Nokia (備選 1) | com.nokia.IMEI | — | — |
| Nokia (備選 2) | com.nokia.mid.imei | — | — |
| Nokia Series 60 | — | com.nokia.mid.cellid | — |
| Nokia Series 40 | — | Cell-ID | — |
| Siemens | com.siemens.imei | — | — |
| Motorola | com.motorola.IMEI | CellID | — |
| Samsung | com.samsung.imei | — | — |
| 通用後備 | IMEI | — | — |
參考資料來源
- MIT 指南:
https://web.mit.edu/21w.780/www/spring2007/guide/
- Nokia 論壇:
https://wiki.forum.nokia.com/index.php/CS000947_-_Getting_Cell_ID_in_Java_ME
- Sun 論壇:
https://forums.sun.com/thread.jspa?threadID=5278668
- Sony Ericsson 開發者:
https://developer.sonyericsson.com/message/110949
實測結果回報
| 機型 | IMEI | Cell ID | 備註 |
| 夏普 SH9010C | ❌ | ❌ | 無法獲取 |
| Sony Ericsson C702 | ✅ | ✅ | 完整支援 |
| Sony Ericsson K818c | ✅ | ✅ | 完整支援 |
歡迎開發者補充更多機型測試結果,共同完善跨廠商相容性矩陣。建議搭配 J2ME Polish 進行編譯時平台分支,單一 JAR 即可多平台部署。