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

J2ME 獲取手機 IMEI 與 Cell ID 完整指南:各廠商實現差異總結

     編輯:J2ME

在 J2ME 開發中,獲取手機的 IMEI(國際移動設備識別碼)和 Cell ID(基站識別碼)是常見需求,但由於這兩個屬性屬於廠商擴展實現,並無統一標準 API。本文整理了主流手機廠商的系統屬性鍵值,並提供可直接用於 J2ME Polish 適配框架的測試代碼,供開發者參考與補充。

資料來源

核心測試代碼(基於 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 Cell ID");
    private Display display = null;

    public GetIMEIAndCellId() {
        display = Display.getDisplay(this);
    }

    protected void destroyApp(boolean unconditional) {}
    protected void pauseApp() {}

    protected void startApp() throws MIDletStateChangeException {
        String platform = 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");
        //#elif polish.vendor==Nokia
        imei = System.getProperty("phone.imei");
        if (imei == null || imei.isEmpty()) {
            imei = System.getProperty("com.nokia.IMEI");
        }
        if (imei == null || imei.isEmpty()) {
            imei = System.getProperty("com.nokia.mid.imei");
        }
        //#if polish.group==Series60
        cellid = System.getProperty("com.nokia.mid.cellid");
        //#elif polish.group==Series40
        cellid = System.getProperty("Cell-ID");
        //#endif
        //#elif polish.vendor==Siemens
        imei = System.getProperty("com.siemens.imei");
        //#elif polish.vendor==Motorola
        imei = System.getProperty("com.motorola.IMEI");
        cellid = System.getProperty("CellID");
        //#elif polish.vendor==Samsung
        imei = System.getProperty("com.samsung.imei");
        //#endif

        if (imei == null || imei.isEmpty()) {
            imei = System.getProperty("IMEI");
        }

        form.append("Platform: " + platform);
        form.append("IMEI: " + imei);
        form.append("Cell ID: " + cellid);
        form.setCommandListener(this);
        form.addCommand(exitCommand);
        display.setCurrent(form);
    }

    public void commandAction(Command cmd, Displayable item) {
        if (cmd == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
}

已知測試結果

  • 夏普 SH9010C:無法獲取 IMEI 與 Cell ID

開發者須知

由於廠商實現差異極大,建議採用「嘗試多組屬性鍵值、優先級排序」的策略。實際部署時請在目標機型上實機測試,並歡迎社群補充更多機型的測試結果。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved