AppSetId | Android API 参考文档 原文标题:AppSetId | API reference | Android Developers
内容概要总结
Android 官方 API 参考,介绍 android.adservices.appsetid.AppSetId 类(在 API level 34 引入,同时存在于 Ad Services Extensions 4)。
AppSetId 是一个唯一的、按设备、按开发者账号、可由用户重置的 ID,用于非变现类广告用例。它表示来自 AppSetIdManager.getAppSetId(Executor, OutcomeReceiver) API 的 appSetID 及其作用域,作用域可以是按 App 或按与用户关联的开发者账号。AppSetId 用于在给定设备上的分析、垃圾信息检测、频次控制和反欺诈用例,即需要跨自有组织拥有的一组 App 关联使用行为或操作的场景。
文档列出两个常量:SCOPE_APP(值 1,作用域为单个 App,设备上所有 App 的 appSetId 各不相同)与 SCOPE_DEVELOPER(值 2,作用域为应用商店上的开发者账号,同一开发者在该设备上的所有 App 共享同一 developer 作用域的 appSetId);以及公开构造函数 AppSetId(String appSetId, int appSetIdScope) 和公开方法 equals、getId、getScope、hashCode 的说明。
翻译内容
原文内容(English)
在 API level 34 中新增
同时存在于 Ad Services Extensions 4
public class AppSetId
extends Object
java.lang.Object
↳ android.adservices.appsetid.AppSetId
一个唯一的、按设备、按开发者账号、可由用户重置的 ID,用于非变现类广告用例。
表示来自 AppSetIdManager.getAppSetId(Executor, OutcomeReceiver) API 的 appSetID 及其作用域。该 ID 的作用域可以是按 App,或按与用户关联的开发者账号。AppSetId 用于在给定设备上的分析、垃圾信息检测、频次控制和反欺诈用例,即可能需要跨自有组织拥有的一组 App 关联使用行为或操作的场景。
摘要(Summary)
常量(Constants)
| 类型 | 常量 | 说明 |
|---|---|---|
| int | SCOPE_APP | appSetId 的作用域为单个 App。 |
| int | SCOPE_DEVELOPER | appSetId 的作用域为应用商店上的开发者账号。 |
公开构造函数(Public constructors)
AppSetId(String appSetId, int appSetIdScope)—— 创建 AppSetId 的一个实例。
公开方法(Public methods)
| 返回类型 | 方法 | 说明 |
|---|---|---|
| boolean | equals(Object o) | 指示某个其他对象是否「等于」此对象。 |
| String | getId() | 获取 appSetId。 |
| int | getScope() | 获取 appSetId 的作用域。 |
| int | hashCode() | 返回该对象的哈希码值。 |
继承的方法(Inherited methods)
来自 java.lang.Object 类。
常量
SCOPE_APP
在 API level 34 中新增。同时存在于 Ad Services Extensions 4。
public static final int SCOPE_APP
appSetId 的作用域为单个 App。设备上所有 App 都会有不同的 appSetId。
常量值:1 (0x00000001)
SCOPE_DEVELOPER
在 API level 34 中新增。同时存在于 Ad Services Extensions 4。
public static final int SCOPE_DEVELOPER
appSetId 的作用域为应用商店上的开发者账号。同一开发者在某设备上的所有 App 都会拥有相同的、developer 作用域的 appSetId。
常量值:2 (0x00000002)
公开构造函数
AppSetId
在 API level 34 中新增。同时存在于 Ad Services Extensions 4。
public AppSetId (String appSetId,
int appSetIdScope)
创建 AppSetId 的一个实例。
参数:
appSetId—— String:由提供方服务生成。该值不能为 null。appSetIdScope—— int:appSetId 的作用域。取值为 SCOPE_APP 或 SCOPE_DEVELOPER。
公开方法
equals
在 API level 34 中新增。
public boolean equals (Object o)
指示某个其他对象是否「等于」此对象。
equals 方法在非 null 对象引用上实现一种等价关系:
- 自反性:对于任何非 null 的引用值 x,x.equals(x) 应返回 true。
- 对称性:对于任何非 null 的引用值 x 和 y,当且仅当 y.equals(x) 返回 true 时,x.equals(y) 应返回 true。
- 传递性:对于任何非 null 的引用值 x、y 和 z,如果 x.equals(y) 返回 true 且 y.equals(z) 返回 true,那么 x.equals(z) 应返回 true。
- 一致性:对于任何非 null 的引用值 x 和 y,只要对象上用于 equals 比较的信息未被修改,多次调用 x.equals(y) 应一致地返回 true 或一致地返回 false。
- 对于任何非 null 的引用值 x,x.equals(null) 应返回 false。
类 Object 的 equals 方法在对象上实现了最具区分度的等价关系;也就是说,对于任何非 null 的引用值 x 和 y,当且仅当 x 和 y 引用同一对象(x == y 的值为 true)时,此方法返回 true。
请注意,每当重写此方法时,通常都需要重写 hashCode 方法,以维护 hashCode 方法的通用契约——即相等的对象必须具有相等的哈希码。
参数:
o—— Object:用于比较的引用对象。
返回:
- boolean:如果此对象与 obj 参数相同则返回 true;否则返回 false。
getId
在 API level 34 中新增。同时存在于 Ad Services Extensions 4。
public String getId ()
获取 appSetId。该 API 始终返回非空的 appSetId。
返回:
- String:该值不能为 null。
getScope
在 API level 34 中新增。同时存在于 Ad Services Extensions 4。
public int getScope ()
获取 appSetId 的作用域。
返回:
- int:取值为 SCOPE_APP 或 SCOPE_DEVELOPER。
hashCode
在 API level 34 中新增。
public int hashCode ()
返回该对象的哈希码值。此方法是为了支持诸如 HashMap 所提供的哈希表而提供的。
hashCode 的通用契约是:
- 在 Java 应用程序的一次执行过程中,只要对象上用于 equals 比较的信息未被修改,对同一对象多次调用 hashCode 方法必须一致地返回同一整数。该整数在应用程序的一次执行到同一应用程序的另一次执行之间不必保持一致。
- 如果根据 equals(Object) 方法两个对象相等,则对这两个对象分别调用 hashCode 方法必须产生相同的整数结果。
- 如果根据 equals(java.lang.Object) 方法两个对象不相等,则不要求对这两个对象分别调用 hashCode 方法产生不同的整数结果。然而,程序员应当意识到,为不相等的对象产生不同的整数结果可能提高哈希表的性能。
在合理可行的范围内,类 Object 定义的 hashCode 方法确实会为不同的对象返回不同的整数。(hashCode 在某个时间点上可能会或可能不会实现为对象内存地址的某个函数。)
返回:
- int:该对象的哈希码值。
本页内容与代码示例受「Content License」中所述许可的约束。Java 和 OpenJDK 是 Oracle 和/或其关联公司的商标或注册商标。
最后更新于 2025-02-10 UTC。
Skip to main content
Essentials
Design & Plan
Develop
Google Play
Blog
More
Android Studio
Sign in
API REFERENCE
Android API Reference
Overview
Privacy Sandbox on Android
Class Index
Package Index
android.adservices
android.adservices.adid
android.adservices.adselection
android.adservices.appsetid
Overview
Classes
AppSetId
AppSetIdManager
android.adservices.common
android.adservices.customaudience
android.adservices.exceptions
android.adservices.measurement
android.adservices.ondevicepersonalization
android.adservices.signals
android.adservices.topics
android.app.sdksandbox
android.app.sdksandbox.sdkprovider
On this page
Summary
Constants
Public constructors
Public methods
Inherited methods
Constants
SCOPE_APP
SCOPE_DEVELOPER
Public constructors
AppSetId
Public methods
equals
getId
getScope
hashCode
Android Developers
Develop
API reference
Added in API level 34
Also in Ad Services Extensions 4
AppSetId
public class AppSetId
extends Object
java.lang.Object
↳ android.adservices.appsetid.AppSetId
A unique, per-device, per developer-account user-resettable ID for non-monetizing advertising usecases.
Represents the appSetID and scope of this appSetId from the AppSetIdManager.getAppSetId(Executor, OutcomeReceiver) API. The scope of the ID can be per app or per developer account associated with the user. AppSetId is used for analytics, spam detection, frequency capping and fraud prevention use cases, on a given device, that one may need to correlate usage or actions across a set of apps owned by an organization.
Summary
Constants
int SCOPE_APP
The appSetId is scoped to an app.
int SCOPE_DEVELOPER
The appSetId is scoped to a developer account on an app store.
Public constructors
AppSetId(String appSetId, int appSetIdScope)
Creates an instance of AppSetId
Public methods
boolean equals(Object o)
Indicates whether some other object is "equal to" this one.
String getId()
Retrieves the appSetId.
int getScope()
Retrieves the scope of the appSetId.
int hashCode()
Returns a hash code value for the object.
Inherited methods
From class java.lang.Object
Constants
SCOPE_APP
Added in API level 34
Also in Ad Services Extensions 4
public static final int SCOPE_APP
The appSetId is scoped to an app. All apps on a device will have a different appSetId.
Constant Value: 1 (0x00000001)
SCOPE_DEVELOPER
Added in API level 34
Also in Ad Services Extensions 4
public static final int SCOPE_DEVELOPER
The appSetId is scoped to a developer account on an app store. All apps from the same developer on a device will have the same developer scoped appSetId.
Constant Value: 2 (0x00000002)
Public constructors
AppSetId
Added in API level 34
Also in Ad Services Extensions 4
public AppSetId (String appSetId,
int appSetIdScope)
Creates an instance of AppSetId
Parameters
appSetId String: generated by the provider service. This value cannot be null.
appSetIdScope int: scope of the appSetId. Value is SCOPE_APP, or SCOPE_DEVELOPER
Public methods
equals
Added in API level 34
public boolean equals (Object o)
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation on non-null object references:
It is reflexive: for any non-null reference value x, x.equals(x) should return true.
It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
For any non-null reference value x, x.equals(null) should return false.
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
Parameters
o Object: the reference object with which to compare.
Returns
boolean true if this object is the same as the obj argument; false otherwise.
getId
Added in API level 34
Also in Ad Services Extensions 4
public String getId ()
Retrieves the appSetId. The api always returns a non-empty appSetId.
Returns
String This value cannot be null.
getScope
Added in API level 34
Also in Ad Services Extensions 4
public int getScope ()
Retrieves the scope of the appSetId.
Returns
int Value is SCOPE_APP, or SCOPE_DEVELOPER
hashCode
Added in API level 34
public int hashCode ()
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.
The general contract of hashCode is:
Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (The hashCode may or may not be implemented as some function of an object's memory address at some point in time.)
Returns
int a hash code value for this object.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
X
Follow @AndroidDev on X
YouTube
Check out Android Developers on YouTube
LinkedIn
Connect with the Android Developers community on LinkedIn
MORE ANDROID
Android
Android for Enterprise
Security
Source
News
Blog
Podcasts
DISCOVER
Gaming
Machine Learning
Health & Fitness
Camera & Media
Privacy
5G
ANDROID DEVICES
Large screens
Wear OS
ChromeOS devices
Android for cars
Android TV
RELEASES
Android 17
Android 16
Android 15
Android 14
Android 13
Android 12
Android 11
DOCUMENTATION AND DOWNLOADS
Android Studio guide
Developers guides
API reference
Download Studio
Android NDK
SUPPORT
Report platform bug
Report documentation bug
Google Play support
Join research studies
Android
Chrome
Firebase
Google Cloud Platform
All products
Privacy
License
Brand guidelines
Get news and tips by email
Subscribe