這一篇是我在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’)。