问题
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
回答1:
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);
回答2:
As per the latest release in Android 10, Restriction on non-resettable device identifiers. pps 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.
Check this for Privacy Changes in Android 10
To avoid such scenarios use UUID.randomUUID().toString()
that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value.
来源:https://stackoverflow.com/questions/58022573/in-android-10-getdeviceid-value-is-null