1、获取手机IMEI,从android 5.0之后通过getImei获取

public static String getIMEI(Context context){String imei = "";try {TelephonyManager tm = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){imei = tm.getDeviceId();}else {Method method = tm.getClass().getMethod("getImei");imei = (String) method.invoke(tm);}} catch (Exception e) {e.printStackTrace();}return imei;}

2、判断哪个卡槽有插卡,从api 23开始,api23之前需要反射来获取,方法名也有所差别

   @TargetApi(Build.VERSION_CODES.M)    public static void JudgeSIM(Context context) {        TelephonyManager tm = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);        //获取当前SIM卡槽数量        int phoneCount = tm.getPhoneCount();        //获取当前SIM卡数量        int activeSubscriptionInfoCount = SubscriptionManager.from(context).getActiveSubscriptionInfoCount();List activeSubscriptionInfoList = SubscriptionManager.from(context).getActiveSubscriptionInfoList();if(activeSubscriptionInfoList == null){return;}for(SubscriptionInfo subInfo : activeSubscriptionInfoList){Logger.d("sim卡槽位置:"+subInfo.getSimSlotIndex());try {Method method = tm.getClass().getMethod("getImei",int.class);String imei = (String) method.invoke(tm,subInfo.getSimSlotIndex());Logger.d("sim卡imei:"+imei);} catch (NoSuchMethodException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();}}Logger.d("卡槽数量:" + phoneCount);        Logger.d("当前SIM卡数量:" + activeSubscriptionInfoCount);    }

更多相关文章

  1. android 编译错误--超出接口数量限制
  2. go语言中控制并发数量的方法
  3. 芋道 Spring Boot JPA 入门(二)之基于方法名查询
  4. PMP项目管理:PMIID与PDU数量速查
  5. SharePoint 解决方案:如何获取Library或者List下的Item数量
  6. 如何在数组中存储产品数量
  7. 在Symfony2中使用Doctrine DQL时检索的记录数量限制
  8. 存储过程,参数数量不正确bug?
  9. 在指定的div - js内按id计算div的数量

随机推荐

  1. 解决DELL R630服务器iDrac8虚拟控制台报
  2. Python算法分为哪几类?具备哪些特征?
  3. jenkins相关
  4. Pod The node had condition: [DiskPress
  5. 前端教程分享:HTTP请求Content-Type你知道
  6. Docker 镜像的备份恢复迁移
  7. 人生首套房子的重要性,怎么买对,怎么置换?
  8. 组件化思维对于一个UI设计来说有多重要?
  9. 如何使gateway_worker与客户端通信,有哪几
  10. thinkphp6 验证码 异步刷新 记录,