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

后端 未结 2 1285
执念已碎
执念已碎 2020-12-10 21:27

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

2条回答
  •  离开以前
    2020-12-10 21:55

    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.

提交回复
热议问题