Android中获取IMEI号
16lz
2021-01-23
原文链接: https://www.jianshu.com/p/c46b6c9b8990
参考网址: https://www.cnblogs.com/fnlingnzb-learner/p/7580691.html
https://www.jianshu.com/p/c46b6c9b8990
/** * 获取手机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 ""; } }
更多相关文章
- DES加解密方法(C#和android通用)
- Android Studio 3.6运行模拟器Emulator警告问题解决方法
- Android使用WebView.loadUri()打开网页的方法
- Android下Multiple markers at this line的解决方法
- Android中延时执行的几种方法
- Android通过SOCKET下载文件的方法