How do I get information about a phone's IMEI in Android 10?

余生长醉 提交于 2019-12-17 20:32:40

问题


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


回答1:


From the Android Developers Documentation Website

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.

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

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:

  • 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.

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.



来源:https://stackoverflow.com/questions/58180656/how-do-i-get-information-about-a-phones-imei-in-android-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!