Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[Ad Services Extensions 4](https://developer.android.com/sdkExtensions)  
Summary:[Methods](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager#pubmethods)\|[Inherited Methods](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager#inhmethods)  

# CustomAudienceManager

`
public


class
CustomAudienceManager
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|---------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.adservices.customaudience.CustomAudienceManager |

<br />

*** ** * ** ***

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

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| ` void`                                                                                                                                                       | ` `[fetchAndJoinCustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager#fetchAndJoinCustomAudience(android.adservices.customaudience.FetchAndJoinCustomAudienceRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Object,java.lang.Exception>))`(`[FetchAndJoinCustomAudienceRequest](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/FetchAndJoinCustomAudienceRequest)` fetchAndJoinCustomAudienceRequest, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[OutcomeReceiver](https://developer.android.com/reference/android/os/OutcomeReceiver)`<`[Object](https://developer.android.com/reference/java/lang/Object)`, `[Exception](https://developer.android.com/reference/java/lang/Exception)`> receiver) ` Adds the user to the[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience)fetched from a`fetchUri`.                                            |
| ` static `[CustomAudienceManager](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager)  | ` `[get](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager#get(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) ` Factory method for creating an instance of CustomAudienceManager.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` `[TestCustomAudienceManager](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/TestCustomAudienceManager) | ` `[getTestCustomAudienceManager](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager#getTestCustomAudienceManager())`() ` Create a service with test-enabling APIs                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` void`                                                                                                                                                       | ` `[joinCustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager#joinCustomAudience(android.adservices.customaudience.JoinCustomAudienceRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Object,java.lang.Exception>))`(`[JoinCustomAudienceRequest](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/JoinCustomAudienceRequest)` joinCustomAudienceRequest, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[OutcomeReceiver](https://developer.android.com/reference/android/os/OutcomeReceiver)`<`[Object](https://developer.android.com/reference/java/lang/Object)`, `[Exception](https://developer.android.com/reference/java/lang/Exception)`> receiver) ` Adds the user to the given[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience).                                                                                                              |
| ` void`                                                                                                                                                       | ` `[leaveCustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager#leaveCustomAudience(android.adservices.customaudience.LeaveCustomAudienceRequest,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Object,java.lang.Exception>))`(`[LeaveCustomAudienceRequest](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/LeaveCustomAudienceRequest)` leaveCustomAudienceRequest, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[OutcomeReceiver](https://developer.android.com/reference/android/os/OutcomeReceiver)`<`[Object](https://developer.android.com/reference/java/lang/Object)`, `[Exception](https://developer.android.com/reference/java/lang/Exception)`> receiver) ` Attempts to remove a user from a custom audience by deleting any existing[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience)data, identified by`ownerPackageName`,`buyer`, and`name`. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public methods

### fetchAndJoinCustomAudience

[**Added in Android UpsideDownCakePrivacySandbox**](https://developer.android.com/preview)  

```
public void fetchAndJoinCustomAudience (FetchAndJoinCustomAudienceRequest fetchAndJoinCustomAudienceRequest, 
                Executor executor, 
                OutcomeReceiver<Object, Exception> receiver)
```

Adds the user to the[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience)fetched from a`fetchUri`.

An attempt to register the user for a custom audience with the same combination of`ownerPackageName`,`buyer`, and`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](https://developer.android.com/reference/java/lang/SecurityException)if

1. the`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](https://developer.android.com/reference/java/lang/IllegalArgumentException)if

1. the storage limit has been exceeded by the calling application and/or
2. any URI parameters in the[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience)given are not authenticated with the[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience)buyer.

This call fails with[LimitExceededException](https://developer.android.com/reference/android/os/LimitExceededException)if the calling package exceeds the allowed rate limits and is throttled.

This call fails with an[IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)if an internal service error is encountered.  
Requires[AdServicesPermissions.ACCESS_ADSERVICES_CUSTOM_AUDIENCE](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/common/AdServicesPermissions#ACCESS_ADSERVICES_CUSTOM_AUDIENCE)

<br />

|                                                                                                                                                                                                                                                                                                            Parameters                                                                                                                                                                                                                                                                                                            ||
|-------------------------------------| |
| `fetchAndJoinCustomAudienceRequest` | `FetchAndJoinCustomAudienceRequest`: This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `executor`                          | `Executor`: This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `receiver`                          | `OutcomeReceiver`: This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

### get

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[Ad Services Extensions 6](https://developer.android.com/sdkExtensions)  

```
public static CustomAudienceManager get (Context context)
```

Factory method for creating an instance of CustomAudienceManager.

<br />

|                                                                  Parameters                                                                  ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------|
| `context` | `Context`: The[Context](https://developer.android.com/reference/android/content/Context)to use This value cannot be`null`. <br /> |

|                                                                                                                                                                      Returns                                                                                                                                                                       ||
|----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [CustomAudienceManager](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager) | A[CustomAudienceManager](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudienceManager)instance This value cannot be`null`. <br /> |

### getTestCustomAudienceManager

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[Ad Services Extensions 4](https://developer.android.com/sdkExtensions)  

```
public TestCustomAudienceManager getTestCustomAudienceManager ()
```

Create a service with test-enabling APIs

<br />

|                                                                                            Returns                                                                                             ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
| [TestCustomAudienceManager](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/TestCustomAudienceManager) | This value cannot be`null`. <br /> |

### joinCustomAudience

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[Ad Services Extensions 4](https://developer.android.com/sdkExtensions)  

```
public void joinCustomAudience (JoinCustomAudienceRequest joinCustomAudienceRequest, 
                Executor executor, 
                OutcomeReceiver<Object, Exception> receiver)
```

Adds the user to the given[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience).

An attempt to register the user for a custom audience with the same combination of`ownerPackageName`,`buyer`, and`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](https://developer.android.com/reference/java/lang/SecurityException)if

1. the`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](https://developer.android.com/reference/java/lang/IllegalArgumentException)if

1. the storage limit has been exceeded by the calling application and/or
2. any URI parameters in the[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience)given are not authenticated with the[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience)buyer.

This call fails with[LimitExceededException](https://developer.android.com/reference/android/os/LimitExceededException)if the calling package exceeds the allowed rate limits and is throttled.

This call fails with an[IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException)if an internal service error is encountered.  
Requires[AdServicesPermissions.ACCESS_ADSERVICES_CUSTOM_AUDIENCE](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/common/AdServicesPermissions#ACCESS_ADSERVICES_CUSTOM_AUDIENCE)

<br />

|                                                                                                                                                                                                                                                                                                        Parameters                                                                                                                                                                                                                                                                                                        ||
|-----------------------------| |
| `joinCustomAudienceRequest` | `JoinCustomAudienceRequest`: This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `executor`                  | `Executor`: This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `receiver`                  | `OutcomeReceiver`: This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

### leaveCustomAudience

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[Ad Services Extensions 4](https://developer.android.com/sdkExtensions)  

```
public void leaveCustomAudience (LeaveCustomAudienceRequest leaveCustomAudienceRequest, 
                Executor executor, 
                OutcomeReceiver<Object, Exception> receiver)
```

Attempts to remove a user from a custom audience by deleting any existing[CustomAudience](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/customaudience/CustomAudience)data, identified by`ownerPackageName`,`buyer`, and`name`.

This call fails with an[SecurityException](https://developer.android.com/reference/java/lang/SecurityException)if

1. the`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](https://developer.android.com/reference/android/os/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.  
Requires[AdServicesPermissions.ACCESS_ADSERVICES_CUSTOM_AUDIENCE](https://developer.android.com/design-for-safety/privacy-sandbox/reference/adservices/common/AdServicesPermissions#ACCESS_ADSERVICES_CUSTOM_AUDIENCE)

<br />

|                                                                                                                                                                                                                                                                                                        Parameters                                                                                                                                                                                                                                                                                                         ||
|------------------------------| |
| `leaveCustomAudienceRequest` | `LeaveCustomAudienceRequest`: This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `executor`                   | `Executor`: This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `receiver`                   | `OutcomeReceiver`: This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |