我是靠谱客的博主 健忘摩托,这篇文章主要介绍Android中获取IMEI号参考网址: https://www.cnblogs.com/fnlingnzb-learner/p/7580691.htmlhttps://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 "";
}
}

 

最后

以上就是健忘摩托最近收集整理的关于Android中获取IMEI号参考网址: https://www.cnblogs.com/fnlingnzb-learner/p/7580691.htmlhttps://www.jianshu.com/p/c46b6c9b8990的全部内容,更多相关Android中获取IMEI号参考网址: https://www内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(156)

评论列表共有 0 条评论

立即
投稿
返回
顶部