使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
广告
广告 ID 库定义了一个接口,用于在运行您应用的不同设备上与系统级广告提供程序进行交互。此接口可让您的应用接收一致的广告 ID 值。
声明依赖项
如需添加 Ads 的依赖项,您必须将 Google Maven 代码库添加到项目中。如需了解详情,请参阅 Google 的 Maven 代码库。
在应用或模块的 build.gradle
文件中添加所需工件的依赖项:
Groovy
dependencies {
implementation 'androidx.ads:ads-identifier:1.0.0-alpha05'
// Optional - add if you're using Guava to handle
// return values of type ListenableFuture.
implementation 'com.google.guava:guava:28.0-android'
}
Kotlin
dependencies {
implementation("androidx.ads:ads-identifier:1.0.0-alpha05")
// Optional - add if you're using Guava to handle
// return values of type ListenableFuture.
implementation("com.google.guava:guava:28.0-android")
}
如需详细了解依赖项,请参阅添加 build 依赖项。
反馈
您的反馈将帮助我们改进 Jetpack。如果您发现了新问题,或对此库有任何改进建议,请告诉我们。创建新问题前,请先查看此库中的现有问题。您可以点击星标按钮,为现有问题投票。
创建新问题
如需了解详情,请参阅问题跟踪器文档。
版本 1.0.0
版本 1.0.0-alpha05
2023 年 3 月 8 日
发布了 androidx.ads:ads-identifier:1.0.0-alpha05
、androidx.ads:ads-identifier-common:1.0.0-alpha05
和 androidx.ads:ads-identifier-provider:1.0.0-alpha05
。版本 1.0.0-alpha05 中包含这些提交内容。
API 变更
版本 1.0.0-alpha04
2020 年 1 月 22 日
发布了 androidx.ads:ads-identifier:1.0.0-alpha04
、androidx.ads:ads-identifier-common:1.0.0-alpha04
和 androidx.ads:ads-identifier-provider:1.0.0-alpha04
。版本 1.0.0-alpha04 中包含这些提交内容。
新功能
API 变更
AdvertisingIdInfo.getId()
现在会直接从 AdvertisingIdProvider
返回广告 ID,因此该 ID 现在可以是任意格式。
版本 1.0.0-alpha03
2019 年 11 月 20 日
发布了 androidx.ads:ads-identifier:1.0.0-alpha03
和 androidx.ads:ads-identifier-common:1.0.0-alpha03
。版本 1.0.0-alpha03 中包含这些提交内容。
问题修复
- 移除了对 Java 8 编程语言的依赖项。此库现在以 Java 7 编程语言为目标。
版本 1.0.0-alpha02
2019 年 9 月 18 日
发布了 androidx.ads:ads-identifier:1.0.0-alpha02
和 androidx.ads:ads-identifier-common:1.0.0-alpha02
。版本 1.0.0-alpha02 中包含这些提交内容。
API 变更
- 已将
AdvertisingIdUtils.getAdvertisingIdProviderServices()
的返回类型从 List<ResolveInfo>
更改为 List<ServiceInfo>
问题修复
- 更改了
AdvertisingIdNotAvailableException
消息,以便更准确地显示“没有兼容的 AndroidX 广告 ID 提供程序”。
版本 1.0.0-alpha01
2019 年 8 月 7 日
发布了 androidx.ads:ads-identifier:1.0.0-alpha01
、androidx.ads:ads-identifier-common:1.0.0-alpha01
和 androidx.ads:ads-identifier-provider:1.0.0-alpha01
。点击此处可查看此版本中包含的提交内容。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Ads\n===\n\n[User Guide](/training/articles/ad-id) \nAPI Reference \n[androidx.ads.identifier](/reference/androidx/ads/identifier/package-summary) \n[androidx.ads.identifier.provider](/reference/androidx/ads/identifier/provider/package-summary) \nThe Advertising ID library defines an interface to interact with system-level ad providers across the devices running your app. This interface allows your app to receive consistent advertising ID values. \n\n| Latest Update | Stable Release | Release Candidate | Beta Release | Alpha Release |\n|---------------|----------------|-------------------|--------------|---------------------------------------------------------------|\n| March 8, 2023 | - | - | - | [1.0.0-alpha05](/jetpack/androidx/releases/ads#1.0.0-alpha05) |\n\nDeclaring dependencies\n----------------------\n\nTo add a dependency on Ads, you must add the Google Maven repository to your\nproject. Read [Google's Maven repository](/studio/build/dependencies#google-maven)\nfor more information.\n\nAdd the dependencies for the artifacts you need in the `build.gradle` file for\nyour app or module: \n\n### Groovy\n\n```groovy\ndependencies {\n implementation 'androidx.ads:ads-identifier:1.0.0-alpha05'\n\n // Optional - add if you're using Guava to handle\n // return values of type ListenableFuture.\n implementation 'com.google.guava:guava:28.0-android'\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n implementation(\"androidx.ads:ads-identifier:1.0.0-alpha05\")\n\n // Optional - add if you're using Guava to handle\n // return values of type ListenableFuture.\n implementation(\"com.google.guava:guava:28.0-android\")\n}\n```\n\nFor more information about dependencies, see [Add build dependencies](/studio/build/dependencies).\n\nFeedback\n--------\n\nYour feedback helps make Jetpack better. Let us know if you discover new issues or have\nideas for improving this library. Please take a look at the\n[existing issues](https://issuetracker.google.com/issues?q=componentid:807287%20status:open)\nin this library before you create a new one. You can add your vote to an existing issue by\nclicking the star button.\n\n[Create a new issue](https://issuetracker.google.com/issues/new?component=807287&template=1390045)\n\nSee the [Issue Tracker documentation](https://developers.google.com/issue-tracker)\nfor more information.\n\nVersion 1.0.0\n-------------\n\n### Version 1.0.0-alpha05\n\nMarch 8, 2023\n\n`androidx.ads:ads-identifier:1.0.0-alpha05`, `androidx.ads:ads-identifier-common:1.0.0-alpha05`, and `androidx.ads:ads-identifier-provider:1.0.0-alpha05` are released. [Version 1.0.0-alpha05 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/0a3d894e8fe0217f1312fb163a89ad51bf15794e..ad9ba647b7548818fc9d4796a03a3b5510166fb3/ads)\n\n**API Changes**\n\n- Deprecated `androidx.ads:ads-identifier` \\& `androidx.ads:ads-identifier-provider`. Please migrate to the [Advertising ID API that's available as part of Google Play Services](https://developers.google.com/android/reference/com/google/android/gms/ads/identifier/AdvertisingIdClient) instead. ([I57791](https://android-review.googlesource.com/#/q/I57791965848891725f98e373d10708e1e525f334))\n\n### Version 1.0.0-alpha04\n\nJanuary 22, 2020\n\n`androidx.ads:ads-identifier:1.0.0-alpha04`, `androidx.ads:ads-identifier-common:1.0.0-alpha04`, and `androidx.ads:ads-identifier-provider:1.0.0-alpha04` are released. [Version 1.0.0-alpha04 contains these commits](https://android.googlesource.com/platform/frameworks/support/+log/73974afa0b122e423606439e6d8e249da523534e..0a3d894e8fe0217f1312fb163a89ad51bf15794e/ads).\n\n**New features**\n\n- Performance improvements.\n\n**API changes**\n\n- `AdvertisingIdInfo.getId()` now returns the Advertising ID from `AdvertisingIdProvider` directly, so the ID could be any format now.\n\n### Version 1.0.0-alpha03\n\nNovember 20, 2019\n\n`androidx.ads:ads-identifier:1.0.0-alpha03` and `androidx.ads:ads-identifier-common:1.0.0-alpha03` are released. [Version 1.0.0-alpha03 contains these commits](https://android.googlesource.com/platform/frameworks/support/+log/561afade39b67853e2b54301e6b0cd16d19ce0a7..73974afa0b122e423606439e6d8e249da523534e/ads).\n\n**Bug fixes**\n\n- Removed dependency on the Java 8 programming language. This library now targets the Java 7 programming language.\n\n### Version 1.0.0-alpha02\n\nSeptember 18, 2019\n\n`androidx.ads:ads-identifier:1.0.0-alpha02` and `androidx.ads:ads-identifier-common:1.0.0-alpha02` are released. [Version 1.0.0-alpha02 contains these commits](https://android.googlesource.com/platform/frameworks/support/+log/886c5f552be88f0d404fbae205244e074a75bb03..561afade39b67853e2b54301e6b0cd16d19ce0a7/ads).\n\n**API changes**\n\n- Changed the return type of `AdvertisingIdUtils.getAdvertisingIdProviderServices()` from `List\u003cResolveInfo\u003e` to `List\u003cServiceInfo\u003e`\n\n**Bug fixes**\n\n- Changed the `AdvertisingIdNotAvailableException` message to more accurately read \"No compatible AndroidX Advertising ID Provider available.\"\n\n### Version 1.0.0-alpha01\n\nAugust 7, 2019\n\n`androidx.ads:ads-identifier:1.0.0-alpha01`,\n`androidx.ads:ads-identifier-common:1.0.0-alpha01`, and\n`androidx.ads:ads-identifier-provider:1.0.0-alpha01` are released. The commits\nincluded in this version can be found\n[here](https://android.googlesource.com/platform/frameworks/support/+log/b2b23e833fc78420c0e1212c35ff1fbf9b327eaf..886c5f552be88f0d404fbae205244e074a75bb03/ads)."]]