For a special kiosk setup I need the IMEI of the device. Since Android 10 it is not possible for regular apps to access device identifiers like the IMEI. However the documentation suggests:
This API requires one of the following:
- If the caller is the device or profile owner, the caller holds the Manifest.permission#READ_PHONE_STATE permission.
- ...
I've set the app as device owner with the following command:
adb shell dpm set-device-owner com.xxxx.xxxx/.AdminReceiver
My manifest contains:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
The IMEI is accessed with the following lines of code:
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
try
{
return telephonyManager.getImei();
}
catch (SecurityException e)
{
return null;
}
I'm still getting SecurityExceptions (with message: The user does not meet the requirements to access device identifiers.). What am I doing wrong?