作者在对待Android 10及以上的用户进行了return " "的操作,但我们在开发的过程中是需要去适配这个型号的用户的,查找了错误描述。
he user 10553 does not meet the requirements to access device identifiers.
通过查看 Google Android开发者官方文档《唯一标识符最佳做法》发现
自 Android 10(API 级别 29)起,您的应用必须是设备或个人资料所有者应用,具有特殊运营商许可,或具有 READ_PRIVILEGED_PHONE_STATE 特权,才能访问不可重置的设备标识符。
所以我们可以使用官方推荐方法,就是文档中看到的,使用SSAID,实例ID、广告ID,随机生成的ID等。
public final class PhoneUtil {
private PhoneUtil() {
throw new UnsupportedOperationException(“u can’t instantiate me…”);
}
/**
- Return the unique device id.
-
If the version of SDK is greater than 28, it will return an empty string.
-
Must hold {@code }