1)在Telephony Framework内部,可以直接使用GSMPhone或GeminiPhone提供的接口。
KK之前的版本:
IMEI(International Mobile Equipment Identity)是国际移动设备身份码,在单卡工程中一个手机对应一个IMEI号,双卡工程中一张卡对应一个IMEI号。
下面是获得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);
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();
2)如需要在SDK开发(第三方APK)中获取IMEI号,请使用TelephonyManager中的getDeviceId()方法,或TelephonyManagerEx(双卡接口)中的getDeviceId(int simId)方法。
Demo code(获取DefaultPhone的IMEI):
import android.telephony.TelephonyManager;
String imei_sim = TelephonyManager.getDeviceId();
Demo code(双卡接口):
import android.telephony.TelephonyManagerEx;
String imei_sim1 = TelephonyManagerEx.getDeviceId(PhoneConstants.GEMINI_SIM_1);
String imei_sim2 = TelephonyManagerEx.getDeviceId(PhoneConstants.GEMINI_SIM_2);
android 中如何获取IMEI号
原创
©著作权归作者所有:来自51CTO博客作者曹观沧海的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Android获取手机IMEI号和IMSI号
位数字)+SP (1位数字),每...
代码示例 Mobile android -
iOS 如何获取 IMEI 如何获取imei号
手机的设备信息,是我们在做证书验证的时候不可缺少的,这里我会写一些我们常用的手机信息获取办法。TelephonyManager是我们手机管理的一个大的类,继承的Object。1核心代码和权限
iOS 如何获取 IMEI android List Mobile