首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> J2ME

J2ME 獲取手機 IMEI 與 Cell ID 完整方案:跨廠商實作總結

     編輯:J2ME

背景與挑戰

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 Ericssoncom.sonyericsson.imeicom.sonyericsson.net.cellidcom.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—
Siemenscom.siemens.imei——
Motorolacom.motorola.IMEICellID—
Samsungcom.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

實測結果回報

機型IMEICell ID備註
夏普 SH9010C❌❌無法獲取
Sony Ericsson C702✅✅完整支援
Sony Ericsson K818c✅✅完整支援
歡迎開發者補充更多機型測試結果,共同完善跨廠商相容性矩陣。建議搭配 J2ME Polish 進行編譯時平台分支,單一 JAR 即可多平台部署。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved