Android 获取IMEI(Android 10以下可用)
16lz
2021-01-23
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); }
更多相关文章
- android 编译错误--超出接口数量限制
- go语言中控制并发数量的方法
- 芋道 Spring Boot JPA 入门(二)之基于方法名查询
- PMP项目管理:PMIID与PDU数量速查
- SharePoint 解决方案:如何获取Library或者List下的Item数量
- 如何在数组中存储产品数量
- 在Symfony2中使用Doctrine DQL时检索的记录数量限制
- 存储过程,参数数量不正确bug?
- 在指定的div - js内按id计算div的数量