如何获取IMEI号和MEID号

IMEI号是GSM的概念,CDMA对应的是MEID号。

IMEI(International Mobile Equipment Identity)是国际移动设备身份码,目前GSM/WCDMA/LTE手机终端需要使用IMEI号码。在单卡工程中一个手机对应一个IMEI号;双卡工程中一张卡对应一个IMEI号,双卡共有两个IMEI号。

MEID (Mobile Equipment Identifier) 移动设备识别码,是CDMA手机的唯一身份识别码。

通过GSMPhone对象来调用getDeviceId()函数,获取到的就是IMEI号。

通过CDMAPhone对象来调用getDeviceId()函数,获取到的就是MEID号。

一、如何获取IMEI号

M0.mp7/M0.mp9版本(包含C2K和非C2K项目)、

M0.mp1版本非C2K项目、

L版本非C2K项目上:

GSMPhone.java中的getDeviceId()

L上面已经没有GeminiPhone;

使用方法如下:


Phone mPhone1=PhoneFactory.getPhone(PhoneConstants.SIM_ID_1);

Phone mPhone2=PhoneFactory.getPhone(PhoneConstants.SIM_ID_2);

 

if (mPhone1 != null) {

    String imei_sim1 =  mPhone1.getDeviceId();

}

if (mPhone2 != null) {

    String imei_sim2 =  mPhone2.getDeviceId();

}

M0.mp1版本C2K项目、

L版本C2K项目上:

L版本C2K项目上,一张卡同时对应一个CDMAPhone和一个GSMPhone,要获取对应卡的IMEI号,需要先获取到对应的GSMPhone对象,具体可以通过下面的方法来获取:

SIM1-> CDMAPhone = PhoneFactory.getPhone(0).getNLtePhone()

SIM1-> GSMPhone = PhoneFactory.getPhone(0).getLtePhone()

SIM2->  CDMAPhone = PhoneFactory.getPhone(1).getNLtePhone()

SIM2->  GSMPhone = PhoneFactory.getPhone(1).getLtePhone()

获取到GSMPhone对象后,通过该对象来调用getDeviceId()函数。

KK版本上:

GSMPhone.java 中getDeviceId()

GeminiPhone.java 其中getDeviceIdGemini()已经没有了,而getDeviceId()获取的是default phone的IMEI;

所以直接使用GSMPhone.java中getDeviceId()方法;

Demo code:

GeminiPhone mGeminiPhone;

String imei_sim1=mGeminiPhone.getPhonebyId(PhoneConstants.GEMINI_SIM_1).getDeviceId();

String imei_sim2=mGeminiPhone.getPhonebyId(PhoneConstants.GEMINI_SIM_2).getDeviceId();

KK之前的版本:

下面是获得IMEI号的接口和demo code

API:

GSMPhone.java 中getDeviceId()

GeminiPhone.java 中getDeviceId() 和 getDeviceIdGemini()

Demo code:

import com.android.internal.telephony.Phone;

import com.android.internal.telephony.gemini.GeminiPhone;

import com.android.internal.telephony.PhoneFactory;  

Phone phone;

phone = PhoneFactory.getDefaultPhone();

String  imei=(GeminiPhone)phone.getDeviceId();

 

GeminiPhone mGeminiPhone;

String imei_sim1 = mGeminiPhone.getDeviceIdGemini(PhoneConstants.GEMINI_SIM_1);

String imei_sim2 = mGeminiPhone.getDeviceIdGemini(PhoneConstants.GEMINI_SIM_2);

二、如何获取MEID号

M0.mp7/M0.mp9版本C2K项目:

通过CDMAPhone.java的getDeviceId()函数来获取。

请在插入电信卡的情况下调用,避免插入非电信卡没有创建CDMAPhone对象,会获取不到。

M0.mp1版本C2K项目、

L版本C2K项目上:

参考上面的说明,要获取MEID号,需要先获取对应卡的CDMAPhone对象,具体可以通过下面的方法来获取:

SIM1-> CDMAPhone = PhoneFactory.getPhone(0).getNLtePhone()

SIM1-> GSMPhone = PhoneFactory.getPhone(0).getLtePhone()

SIM2->  CDMAPhone = PhoneFactory.getPhone(1).getNLtePhone()

SIM2->  GSMPhone = PhoneFactory.getPhone(1).getLtePhone()

获取到CDMAPhone对象后,通过该对象来调用getDeviceId()函数。

如果电信卡插在卡1上,则使用上面SIM1的方法来获取卡1的CDMAPhone对象。

如果电信卡插在卡2上,则使用上面 SIM2 的方式来获取卡2的CDMAPhone对象。

如果同时插入两张电信卡,由于同一时刻只支持一张电信卡,则只有主卡可以获取到MEID号,可以通过PhoneFactory.getDefaultPhone().getNLtePhone() 来获取主卡的CDMAPhone对象。

发布了87 篇原创文章 · 获赞 157 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/u012932409/article/details/103434656