2013-02-27 97 views

回答

2

它應該工作。我剛剛在我的CDMA Galaxy聯網上測試了它,並且它返回了一個值,儘管它根本沒有SIM卡。當我在模擬器上運行它時,它返回了一長串零。

更新:根據documentation,getDeviceId()返回GSM設備的IMEI。而IMEI不是SIM卡功能,它隨設備一起提供。

+0

不幸的是,我現在沒有辦法在有SIM卡的設備上測試它,但我可能會在幾個小時之內。 – 2013-02-28 00:51:56

+0

謝謝你,測試過了,它的工作! – Nikita 2013-02-28 09:06:41

1

代碼會談:

telephony.getDeviceId()最後調用Phone.getDeviceId(),這個方法的實現是不同的電話就像CDMA手機和GSM手機上的不同。例如,CDMA電話。

public String getMeid() { 
    return mMeid; 
} 
//returns MEID or ESN in CDMA 
public String getDeviceId() { 
    String id = getMeid(); 
    if ((id == null) || id.matches("^0*$")) { 
     Rlog.d(LOG_TAG, "getDeviceId(): MEID is not initialized use ESN"); 
     id = getEsn(); 
    } 
    return id; 
} 

它沒有檢查那個SIM ABSENT狀態。所以當然你可以在沒有SIM卡的情況下得到結果。

但是,看看這個mMeid何時重置。

case EVENT_GET_IMEI_DONE: 
      ar = (AsyncResult)msg.obj; 

      if (ar.exception != null) { 
       break; 
      } 

      mImei = (String)ar.result; 
case EVENT_RADIO_AVAILABLE: { 
      mCM.getBasebandVersion(
        obtainMessage(EVENT_GET_BASEBAND_VERSION_DONE)); 

      mCM.getIMEI(obtainMessage(EVENT_GET_IMEI_DONE)); 
      mCM.getIMEISV(obtainMessage(EVENT_GET_IMEISV_DONE)); 
     } 

因此,它會在收到EVENT_RADIO_AVAILABLE消息時重置。並且該事件從RIL發送。只有當它收到EVENT_RADIO_AVAILABLE消息時,它纔會發出一條消息來請求設備標識。儘管獲取設備身份與SIM卡無關,但EVENT_RADIO_AVAILABLE可能會(需要進一步確認)。

我進一步檢查系統何時發出EVENT_RADIO_AVAILABLE消息。最後發現RadioState包含:

enum RadioState { 
    RADIO_OFF,   /* Radio explictly powered off (eg CFUN=0) */ 
    RADIO_UNAVAILABLE, /* Radio unavailable (eg, resetting or not booted) */ 
    SIM_NOT_READY,  /* Radio is on, but the SIM interface is not ready */ 
    SIM_LOCKED_OR_ABSENT, /* SIM PIN locked, PUK required, network 
          personalization, or SIM absent */ 
    SIM_READY,   /* Radio is on and SIM interface is available */ 
    RUIM_NOT_READY, /* Radio is on, but the RUIM interface is not ready */ 
    RUIM_READY,  /* Radio is on and the RUIM interface is available */ 
    RUIM_LOCKED_OR_ABSENT, /* RUIM PIN locked, PUK required, network 
           personalization locked, or RUIM absent */ 
    NV_NOT_READY,  /* Radio is on, but the NV interface is not available */ 
    NV_READY;   /* Radio is on and the NV interface is available */ 
    ... 
} 

當isAvailable()返回true時,它會發出事件。 imei將會更新。

public boolean isAvailable() { 
    return this != RADIO_UNAVAILABLE; 
} 

因此,SIM_ABSENT與設備ID無關。

+0

謝謝你的這個偉大的解釋 – Nikita 2013-02-28 09:07:03

相關問題