ANDROID_ID 仍可用于 Android 10

Seb*_*ine 11 android identifier kotlin

根据谷歌的说法,在没有一些先决条件的情况下,Android 10 系统上不应访问 ANDROID_ID(也称为 SSAID)(请参阅:https : //developer.android.com/about/versions/10/privacy/changes

• If your app targets Android 10 or higher, a SecurityException occurs.

• If your app targets Android 9 (API level 28) or lower, the method
  returns null or placeholder data if the app has the READ_PHONE_STATE
  permission. Otherwise, a SecurityException occurs.
Run Code Online (Sandbox Code Playgroud)

我的问题是,我仍然可以在没有上述任何先决条件的情况下访问 ANDROID_ID。

我创建了一个目标平台为 Android 10 API 级别 29 的 Kotlin 项目。

在这个项目中,我运行了以下代码:

• If your app targets Android 10 or higher, a SecurityException occurs.

• If your app targets Android 9 (API level 28) or lower, the method
  returns null or placeholder data if the app has the READ_PHONE_STATE
  permission. Otherwise, a SecurityException occurs.
Run Code Online (Sandbox Code Playgroud)

结果是,ANDROID_ID 被毫无问题地写入 logcat。该值不是虚拟值,而是实际的 ANDROID_ID。这已经在模拟器和真实设备(Pixel 2)上进行了测试。

Poo*_*rya 5

也许为时已晚,但根据 android O android developer's blog 中的这篇文章

  • 只要软件包名称和签名密钥相同,ANDROID_ID 值在软件包卸载/重新安装时就不会改变。应用程序可以依靠此值在重新安装时保持状态。
  • 如果应用安装在运行较早版本 Android 的设备上,当设备更新到 Android O 时,Android ID 保持不变,除非卸载并重新安装该应用。
  • 仅当设备恢复出厂设置或签名密钥在卸载和重新安装事件之间轮换时,Android ID 值才会更改。
  • 此更改仅适用于随附 Google Play 服务和广告 ID 的设备制造商。其他设备制造商可能会提供替代的可重置 ID 或继续提供 ANDROID ID。