Buy Reviews
Powered by MaxBlogPress  

在Java ME中取得Cell ID

點閱人數:71次 七月 20th, 2009 by ㄚ琪 |

這一篇是我在CS000947 – Getting Cell ID in Java ME的中文翻譯,網址在在Java ME中取得Cell ID
為了備份,並轉貼在此:

ID CS000947 Creation date May 14, 2008
Platform Series 40 3rd Edition, FP1 and S60 3rd Edition, FP2 Tested on devices
Category Java Subcategory MIDP 2.0
Keywords (APIs, classes, methods, functions): System.getProperty(), Nokia proprietary system properties

概論

這個程式碼描述在S40及S60系列的機器上如何使用Nokia-proprietary的系統屬性取得手機的cell ID,注意在不同系列的機器上需使用不同的系統屬性:

Series 40 3rd Edition, FP1 (或較新的):

System.getProperty("Cell-ID")

S60 3rd Edition, FP2 (或較新的):

System.getProperty("com.nokia.mid.cellid")

注意: 在S40機器上MIDlet需要製造商或運銷區域的簽名,否則這個屬性會是空值,S60的機上不需要簽名。

原始碼

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class CellIDMIDlet extends MIDlet implements CommandListener {
    private Form form;
    private Command exitCommand;
    private String S40_cell_id;   // Series 40 cell id property
    private String S60_cell_id;   // S60 cell id property

    public void startApp() {
        form = new Form("Getting Cell ID");
        S40_cell_id = System.getProperty("Cell-ID");
        S60_cell_id = System.getProperty("com.nokia.mid.cellid");
        form.append("Series 40 devices: " + S40_cell_id + "\n");
        form.append("S60 devices: " + S60_cell_id);
        exitCommand = new Command("Exit", Command.EXIT, 1);
        form.setCommandListener(this);
        form.addCommand(exitCommand);
        Display.getDisplay(this).setCurrent(form);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if (c == exitCommand) this.notifyDestroyed();
    }
}

後處理

當MIDlet在S40或S60系列的機器上執行時,cell ID會顯示在表單上(一個有數值另一個有’null’)。

另見

Java ME系統屬性

喜歡這篇文章嗎?請幫這篇加入共用書籤,謝謝:
  • Digg
  • del.icio.us
  • Google Bookmarks
  • Hemidemi
  • MyShare
  • Technorati
  • StumbleUpon
  • Diigo
  • Facebook
  • Twitter

Random Posts

發表迴響

名稱:(必)
電子郵件(並不會被發佈)(必)
個人網站

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>