• android 中怎样获取IMEI号


    1)在Telephony Framework内部。能够直接使用GSMPhone或GeminiPhone提供的接口。
    KK之前的版本号:
    IMEI(International Mobile Equipment Identity)是国际移动设备身份码。在单卡project中一个手机相应一个IMEI号,双卡project中一张卡相应一个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);

  • 相关阅读:
    华为上机:IP地址转换
    华为上机:统计给定的两个数之间的素数的个数
    华为上机:五子棋
    华为上机:树的遍历
    华为上机:Tom的生日礼物
    华为上机:求2的N次幂的值
    2016搜狗:矩阵元素相乘
    欢迎使用CSDN-markdown编辑器
    lintcode:最大间隔
    lintcode:删除链表中指定元素
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8690050.html
Copyright © 2020-2023  润新知