CustomAudienceManager


public abstract class CustomAudienceManager


This class provides APIs for app and ad-SDKs to join / leave custom audiences.

Summary

Public methods

abstract void
@ExperimentalFeatures.Ext10OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
fetchAndJoinCustomAudience(
    @NonNull FetchAndJoinCustomAudienceRequest request
)

Adds the user to the CustomAudience fetched from a {@code fetchUri}.

abstract void
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
joinCustomAudience(@NonNull JoinCustomAudienceRequest request)

Adds the user to the given CustomAudience.

abstract void
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
leaveCustomAudience(@NonNull LeaveCustomAudienceRequest request)

Attempts to remove a user from a custom audience by deleting any existing CustomAudience data, identified by {@code ownerPackageName}, {@code buyer}, and {@code name}.

static final CustomAudienceManager

Creates CustomAudienceManager.

Public methods

fetchAndJoinCustomAudience

Added in 1.1.0-beta06
@ExperimentalFeatures.Ext10OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
public abstract void fetchAndJoinCustomAudience(
    @NonNull FetchAndJoinCustomAudienceRequest request
)

Adds the user to the CustomAudience fetched from a {@code fetchUri}.

An attempt to register the user for a custom audience with the same combination of {@code ownerPackageName}, {@code buyer}, and {@code name} will cause the existing custom audience's information to be overwritten, including the list of ads data.

Note that the ads list can be completely overwritten by the daily background fetch job.

This call fails with an SecurityException if

  1. the {@code ownerPackageName} is not calling app's package name and/or
  2. the buyer is not authorized to use the API.

This call fails with an IllegalArgumentException if

  1. the storage limit has been exceeded by the calling application and/or
  2. any URI parameters in the [CustomAudience] given are not authenticated with the [CustomAudience] buyer.

This call fails with LimitExceededException if the calling package exceeds the allowed rate limits and is throttled.

This call fails with an IllegalStateException if an internal service error is encountered.

This call fails with an UnsupportedOperationException if the Android API level and AdServices module versions don't support this API.

Parameters
@NonNull FetchAndJoinCustomAudienceRequest request

The request to fetch and join custom audience.

joinCustomAudience

Added in 1.0.0
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
public abstract void joinCustomAudience(@NonNull JoinCustomAudienceRequest request)

Adds the user to the given CustomAudience.

An attempt to register the user for a custom audience with the same combination of {@code ownerPackageName}, {@code buyer}, and {@code name} will cause the existing custom audience's information to be overwritten, including the list of ads data.

Note that the ads list can be completely overwritten by the daily background fetch job.

This call fails with an SecurityException if

  1. the {@code ownerPackageName} is not calling app's package name and/or
  2. the buyer is not authorized to use the API.

This call fails with an IllegalArgumentException if

  1. the storage limit has been exceeded by the calling application and/or
  2. any URI parameters in the [CustomAudience] given are not authenticated with the [CustomAudience] buyer.

This call fails with LimitExceededException if the calling package exceeds the allowed rate limits and is throttled.

This call fails with an IllegalStateException if an internal service error is encountered.

Parameters
@NonNull JoinCustomAudienceRequest request

The request to join custom audience.

leaveCustomAudience

Added in 1.0.0
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
public abstract void leaveCustomAudience(@NonNull LeaveCustomAudienceRequest request)

Attempts to remove a user from a custom audience by deleting any existing CustomAudience data, identified by {@code ownerPackageName}, {@code buyer}, and {@code name}.

This call fails with an SecurityException if

  1. the {@code ownerPackageName} is not calling app's package name; and/or
  2. the buyer is not authorized to use the API.

This call fails with LimitExceededException if the calling package exceeds the allowed rate limits and is throttled.

This call does not inform the caller whether the custom audience specified existed in on-device storage. In other words, it will fail silently when a buyer attempts to leave a custom audience that was not joined.

Parameters
@NonNull LeaveCustomAudienceRequest request

The request to leave custom audience.

obtain

Added in 1.0.0
public static final CustomAudienceManager obtain(@NonNull Context context)

Creates CustomAudienceManager.

Returns
CustomAudienceManager

CustomAudienceManager object. If the device is running an incompatible build, the value returned is null.