Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Android 10 getDeviceID value is null

In android 10, couldn't get device id using permission "READ_PHONE_STATE". I got an error while trying to get deviceID "The user 10296 does not meet the requirements to access device identifiers". I referred the developer site, but couldn't get proper solution. Also "READ_PRIVILEGE_PHONE_STATE" permission also not accessible.

Please prefer any solution to get deviceID from Android 10 mobile's and help me to resolve this issue. Thanks in advance

like image 821
Arun Kumar Avatar asked Apr 30 '26 06:04

Arun Kumar


2 Answers

getDeviceId() has been deprecated since API level 26.

"READ_PRIVILEGE_PHONE_STATE" is only accessible by The best practices suggest that you should "Avoid using hardware identifiers." for unique identifiers. You can use an instance id from firebase e.g FirebaseInstanceId.getInstance().getId();.

Or you can generate a custom globally-unique ID (GUID) to uniquely identify the app instance e.g String uniqueID = UUID.randomUUID().toString();

or the least recommended way

String deviceId = android.provider.Settings.Secure.getString(
                context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
like image 141
Joe Malebe Avatar answered May 12 '26 09:05

Joe Malebe


You can also use this one, it's getting token from Firebase:-

String deviceId = FirebaseInstanceId.getInstance().getToken();

and this way is also working:-

String deviceId = UUID.randomUUID().toString();

like image 28
Amit Sharma Avatar answered May 12 '26 09:05

Amit Sharma