我有一个简单的问题:TelephonyManager.getDeviceId可以在没有SIM卡的情况下工作吗?
是否
TelephonyManager.getDeviceId();
将在设备没有SIM卡(SIM_STATE_ABSENT)工作?
我有一个简单的问题:TelephonyManager.getDeviceId可以在没有SIM卡的情况下工作吗?
是否
TelephonyManager.getDeviceId();
将在设备没有SIM卡(SIM_STATE_ABSENT)工作?
它应该工作。我刚刚在我的CDMA Galaxy联网上测试了它,并且它返回了一个值,尽管它根本没有SIM卡。当我在模拟器上运行它时,它返回了一长串零。
更新:根据documentation,getDeviceId()返回GSM设备的IMEI。而IMEI不是SIM卡功能,它随设备一起提供。
不幸的是,我现在没有办法在有SIM卡的设备上测试它,但我可能会在几个小时之内。 – 2013-02-28 00:51:56
谢谢你,测试过了,它的工作! – Nikita 2013-02-28 09:06:41
代码会谈:
的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无关。
谢谢你的这个伟大的解释 – Nikita 2013-02-28 09:07:03
它应该。设备ID在设备中,而不在SIM卡上。 – 2013-02-27 22:35:49