Access getDeviceID() for a Device Owner App Android 10?

647 Views Asked by At

I have many phones I need to register in a database with IMEI barcodes and install a company app on it to connect and track them. For this purpose I need to access the IMEI with getDeviceID(). Since Android 10, it is not as simple.

In this page, Android says if you are device owner you can access it : https://developer.android.com/training/articles/user-data-ids

I use this method to make my app a device owner app : How to make my app a device owner?

adb shell dpm set-device-owner com.package.name/.MyDeviceAdminReceiver 

When I use getDeviceId() in the app, I still have the error :

 java.lang.SecurityException: getDeviceId: The user 10180 does not meet the requirements to access device identifiers.

Why this method doesn't work ? Do you have any suggestions to the IMEI ?

1

There are 1 best solutions below

0
bwt On

Setting your application as device owner is not sufficient, you also need it to complete the provisioning flow. For Android up to 11 it is started by launching ACTION_PROVISION_MANAGED_DEVICE, for Android 12 you have to listen to ACTION_GET_PROVISIONING_MODE

Google provides a sample DPC.