本篇是本人收集到的怎麼獲取手機的Imei和cellid的總結,由於這兩個屬性是每個廠商自己實現,故而沒有同一的方法。本人收集的也不全,測試亦是不全面。放置一篇文章在這裡,希看有愛好的人多多補充。
材料起源如下:
http://web.mit.edu/21w.780/www/spring2007/guide/
http://wiki.forum.nokia.com/index.PHP/CS000947_-_Getting_Cell_ID_in_Java_ME
http://forums.sun.com/thread.JSPa?threadID=5278668
https://developer.sonyeriCSSon.com/message/110949
測試代碼如下,當中應用了polish做適配:
package study;
import Javax.microedition.lcdui.Command;
import Javax.microedition.lcdui.CommandListener;
import Javax.microedition.lcdui.Display;
import Javax.microedition.lcdui.Displayable;
import Javax.microedition.midlet.MIDlet;
import Javax.microedition.midlet.MIDletStateChangeException;
import de.enough.polish.ui.Form;
/**
*
* @author: zhang*** [email protected]
* @version: 0.1
* @time: 2008-8-10 下午01:56:17
*
*/
public class GetIMEIAndCellId extends MIDlet implements CommandListener {
private Command exitCommand = new Command("exit", Command.EXIT, 1);
Form form = new Form("imei and cellid");
Display display = null;
public GetIMEIAndCellId() {
display = Display.getDisplay(this);
}
protected void destroyApp(boolean arg0) {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
//獲取系統信息
String info = System.getProperty("microedition.platform ");
//獲取到imei號碼
String imei = "";
//cellid
String cellid = "";
//lac
String lac = "";
//#if polish.vendor==Sony-EriCSSon
imei = System.getProperty("com.sonyeriCSSon.imei");
//參考 http://forums.sun.com/thread.JSPa?threadID=5278668
//https://developer.sonyeriCSSon.com/message/110949
cellid = System.getProperty("com.sonyeriCSSon.Net.cellid ");
//獲取索愛機子的
lac = System.getProperty("com.sonyeriCSSon.Net.lac");
//#else if polish.vendor==諾基亞
imei = System.getProperty("phone.imei");
if (imei == null || "".equals(imei)) {
imei = System.getProperty("com.nokia.IMEI");
}
if (imei == null || "".equals(imei)) {
imei = System.getProperty( "com.nokia.mid.imei");
}
//獲取到cellid
//參考http://wiki.forum.nokia.com/index.PHP/CS000947_-_Getting_Cell_ID_in_Java_ME
//#if polish.group==SerIEs60
cellid = System.getProperty("com.nokia.mid.cellid");
//#else if polish.group==SerIEs40
cellid = System.getProperty("Cell-ID");
//#endif
//#else if polish.vendor==SIEmens
imei = System.getProperty("com.sIEmens.imei");
//#else if polish.vendor==Motorola
imei = System.getProperty("com.motorola.IMEI");
//cellid 參考 http://web.mit.edu/21w.780/www/spring2007/guide/
cellid = System.getProperty("CellID");
//#else if polish.vendor==Samsung
imei = System.getProperty("com.samsung.imei");
//#endif
if (imei == null || "".equals(imei)) {
imei = System.getProperty("IMEI");
}
//展現出來
form.append("platforminfo:" + info);
form.append("imei:" + imei);
form.append("cellid:" + cellid);
form.setCommandListener(this);
form.addCommand(exitCommand);
display.setCurrent(form);
}
public void commandAction(Command cmd, Displayable item) {
if (cmd == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
目前我手機的測試成果如下,希看大家能夠補充測試成果或者指出文中纰漏之處:
夏普-sh9010c:不能夠獲取
sonyeriCSSon:
c702,k818c:能夠獲取imei及cellid