Build.GetSerial() returns 未知 API 29

Build.GetSerial() returns unknown on API 29

我无法在 android 10 设备上获取序列号。

我知道一切(权限,运行时权限,我只有在授予权限后才能序列化)从这里

我的代码适用于所有 android 版本,除了 10

你有什么想法吗?

如果你按照这里的官方文档:https://developer.android.com/reference/android/os/Build.html#getSerial(), more info on Android 10 changes here

您会注意到从 Android 10 开始,此方法返回 Build.UNKNOWN。您不能再使用它来唯一标识单个设备

您需要切换到名为 Settings.Secure.ANDROID_ID

的“较少”持久性版本

绕过此限制的唯一方法是:

  1. Create a system app to be able to get the READ_PRIVILEGED_PHONE_STATE system permission (a normal app can't get this).
  2. Be registered as a carrier (which requires you to have built the Android ROM)
  3. Have a custom "work profile" to set your own policies in the device.

如您所想,所有这些选项并不意味着标准 android 应用程序开发人员会使用