首先刚看见这个需求,觉得有病吧。没办法也得解决。以下方法亲测有效,希望能帮助到大家。

 首先我们应该注意的是需要一个权限,要不怎么都不会成功的

 

 接着就是代码部分了,在网上找了好多资料都没有生效 亲测下面代码有效

//whx import com.android.internal.telephony.PhoneConstants; import android.telephony.TelephonyManager;

 TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE); String imei = telephonyManager.getDeviceId();

这样我们就获取到了单卡的IMEI号码了。

 如果想要获取到双卡的:

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) {            String imei = telephonyManager.getDeviceId(slot);}

以上方法就可以让我们获取到IMEI号码了。有木有觉得很棒!

我们在放出来资料,希望能帮助到大家

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

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

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

 

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

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

 

一、如何获取IMEI


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 phoneIMEI

所以直接使用GSMPhone.javagetDeviceId()方法 

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);


更多相关文章

  1. Android开发之Memory类的分析
  2. Android(安卓)Handler Message Looper机制原理
  3. Android(安卓)设计模式之面向对象的六大原则
  4. 新建Android项目的时候,选择SDK的区别
  5. android中判断sim卡状态和读取联系人资料的方法
  6. 检索Android的图片库,并显示
  7. EditText的几种事件用法
  8. Android中xml文件的解析
  9. Camera框架初探

随机推荐

  1. Android中的inputType属性简单用法.
  2. Android(安卓)xml资源文件中@、@android:
  3. Android内核学习笔记
  4. Android相对布局属性全集
  5. Android异步处理系列文章四篇之三
  6. Android(安卓)xml资源文件中@、@android:
  7. android中的ellipsize
  8. Android(安卓)自定义shape圆形按钮
  9. Android最佳实战连接
  10. Android(安卓)相对布局属性