如何获取有关Android 10中手机的IMEI的信息? [英] How do I get information about a phone's IMEI in Android 10?

查看:3433
本文介绍了如何获取有关Android 10中手机的IMEI的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android 10之前,我使用 TelephonyManager API来检索该信息,但在Android 10中不再起作用.

Before Android 10, I was using the TelephonyManager API to retrieve that info, but it's no longer working in Android 10.

推荐答案

来自

从Android 10开始,应用必须具有READ_PRIVILEGED_PHONE_STATE特权,才能访问设备的不可重置标识符,包括IMEI和序列号.

Starting in Android 10, apps must have the READ_PRIVILEGED_PHONE_STATE privileged permission in order to access the device's non-resettable identifiers, which include both IMEI and serial number.

从Google Play商店安装的第三方应用无法声明特权.

Third-party apps installed from the Google Play Store cannot declare privileged permissions.

如果您的应用没有权限,并且无论如何您都尝试询问有关不可重置标识符的信息,则平台的响应会根据目标SDK版本而有所不同:

If your app doesn't have the permission and you try asking for information about non-resettable identifiers anyway, the platform's response varies based on target SDK version:

  • 如果您的应用定位到Android 10或更高版本,则会发生SecurityException.
  • 如果您的应用程序针对Android 9(API级别28)或更低版本,则如果该应用程序具有READ_PHONE_STATE权限,则该方法将返回null或占位符数据.否则,将发生SecurityException.
  • If your app targets Android 10 or higher, a SecurityException occurs.
  • If your app targets Android 9 (API level 28) or lower, the method returns null or placeholder data if the app has the READ_PHONE_STATE permission. Otherwise, a SecurityException occurs.

如果您尝试访问它,它将引发以下异常: java.lang.SecurityException: getImeiForSlot: The user 10180 does not meet the requirements to access device identifiers.

If you try to access it, it throws the below exception: java.lang.SecurityException: getImeiForSlot: The user 10180 does not meet the requirements to access device identifiers.

这篇关于如何获取有关Android 10中手机的IMEI的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆