Android中获取IMEI号

编程入门 行业动态 更新时间:2024-10-05 17:27:57

<a href=https://www.elefans.com/category/jswz/34/1771384.html style=Android中获取IMEI号"/>

Android中获取IMEI号

参考网址: .html

    /*** 获取手机IMEI号** 需要动态权限: android.permission.READ_PHONE_STATE*/public static String getIMEI(Context context) {TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);@SuppressLint("MissingPermission")String imei = telephonyManager.getDeviceId();@SuppressLint({"NewApi", "MissingPermission", "LocalSuppress"})String str = telephonyManager.getImei();String id = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);return imei;}
//没有量产的手机(水货)它可能有无效的IMEI,如:0000000000000;通过上边的方法有可能获取到,也有可能获取不到/**这个方法一定可以获取到* @param slotId  slotId为卡槽Id,它的值为 0、1;* @return*/public static String getIMEI(Context context, int slotId) {try {TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);Method method = manager.getClass().getMethod("getImei", int.class);String imei = (String) method.invoke(manager, slotId);return imei;} catch (Exception e) {return "";}}

 

更多推荐

Android中获取IMEI号

本文发布于:2024-02-28 09:23:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1768728.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android   IMEI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!