So, I'm developing an app for enterprise-owned mobile phones, which are managed by Knox and Intune.
How do I get the device's IMEI programmatically?
I tried integrating the Intune and Graph SDKs but they are of no use, there's no explicit way to grant the READ_PRIVILEGED_PHONE_STATE permission to the app and no method or something to get that information.
And no, using the generic Android ID or other IDs won't do the job, it's mandatory that I get the IMEI programmatically for this use case.
Thanks in advance :)
I know that accessing the IMEI using the
READ_PRIVILEGED_PHONE_STATEpermission in Android is not recommended. Starting from Android 10 (API level 29) and above, access to IMEI is restricted for privacy and security reasons. However, you can use theTelephonyManagerclass to retrieve device-related information, such as the IMEI, on Android devices running on older versions before Android 10. By the way, it's not recommended to get IMEI, but you can useAndroid ID (Secure Setting Android ID - SSAID)(it's recommended), also you can getFirebase (FID)(it's recommended), or generateGUID(fair practice), or my personal experience you can get WIFI or Bluetooth Mac Address (but remember it's not recommended too)... references: Firebase, Android, Amazonif it's necessary to have IMEI you should be sure the device's OS is below Android 10 else it won't work. First, make sure you grant
READ_PHONE_STATEpermission, then here is the code: