Select platform: [Android (beta)
![New](https://developers.google.com/static/admob/images/new.svg)](https://developers.google.com/admob/android/next-gen/privacy "View this page for the Android (beta) platform docs.") [Android](https://developers.google.com/admob/android/privacy "View this page for the Android platform docs.") [iOS](https://developers.google.com/admob/ios/privacy "View this page for the iOS platform docs.") [Unity](https://developers.google.com/admob/unity/privacy "View this page for the Unity platform docs.") [Flutter](https://developers.google.com/admob/flutter/privacy "View this page for the Flutter platform docs.")  

The Google User Messaging Platform (UMP) SDK is a privacy and messaging tool to
help you manage privacy choices. For more information, see

[About Privacy \& messaging](https://support.google.com/admob/answer/10107561).


## Prerequisites

- Android API level 21 or higher


## Create a message type

Create user messages with one of the

[Available user message types](https://support.google.com/admob/answer/10114020)

under the **Privacy \& messaging** tab of your

AdMob

account. The UMP SDK attempts to display a
privacy message created from the AdMob Application ID
set in your project.

For more details, see

[About privacy and messaging](https://support.google.com/admob/answer/10107561).


## Install with Gradle

Add the dependency for the Google User Messaging Platform SDK to your module's
app-level [Gradle](https://gradle.org) file, normally `app/build.gradle`:  

    dependencies {
      implementation("com.google.android.ump:user-messaging-platform:4.0.0")
    }

After making the changes to your app's `build.gradle`, be sure to sync your
project with Gradle files.


## Add the application ID

You can find your application ID in the

[AdMob UI](https://support.google.com/admob/answer/7356431#find-an-app-id).

Add the ID to your

`AndroidManifest.xml`

with the following code snippet:

    <manifest>
      <application>
        \<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-xxxxxxxxxxxxxxxx\~yyyyyyyyyy"/\>
      </application>
    </manifest>

<br />

## Get the user's consent information

To get the user's consent information, do the following:

Declare an instance of `ConsentInformation`:  

### Java

    private final ConsentInformation consentInformation;

### Kotlin

    private lateinit val consentInformation: ConsentInformation

Initialize the `ConsentInformation` instance:  

### Java

    consentInformation = UserMessagingPlatform.getConsentInformation(context);

### Kotlin

    consentInformation = UserMessagingPlatform.getConsentInformation(context)

You should request an update of the user's consent information at every app
launch, using `
`[requestConsentInfoUpdate()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#public-abstract-void-requestconsentinfoupdate-activity-activity,-consentrequestparameters-consentrequestparameters,-consentinformation.onconsentinfoupdatesuccesslistener-successlistener,-consentinformation.onconsentinfoupdatefailurelistener-failurelistener). This request checks the following:

- **Whether consent is required**. For example, consent is required for the first time, or the previous consent decision expired.
- **Whether a privacy options entry point is required**. Some privacy messages require apps to allow users to modify their privacy options at any time.

### Java


    // Requesting an update to consent information should be called on every app launch.
    consentInformation.requestConsentInfoUpdate(
        activity,
        params,
        () -> // Called when consent information is successfully updated.
        requestConsentError -> // Called when there's an error updating consent information.  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.java#L88-L99

### Kotlin


    // Requesting an update to consent information should be called on every app launch.
    consentInformation.requestConsentInfoUpdate(
      activity,
      params,
      {
        // Called when consent information is successfully updated.
      },
      { requestConsentError ->
        // Called when there's an error updating consent information.
      },
    )  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.kt#L73-L89

| **Warning:** Using other ways of checking consent status, such as the cache on your app or a previously saved consent string, can lead to a [TCF 3.3 error](https://support.google.com/admanager/answer/9999955) if consent is expired.

## Load and present the privacy message form

After you have received the most up-to-date consent status, call
`
`[loadAndShowConsentFormIfRequired()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/UserMessagingPlatform#loadAndShowConsentFormIfRequired(android.app.Activity,%20com.google.android.ump.ConsentForm.OnConsentFormDismissedListener)) to load any forms required to
collect user consent. After loading, the forms present immediately.
**Key Point:** If no privacy message forms require collection of user consent prior to requesting ads, the callback is invoked immediately.  

### Java


    UserMessagingPlatform.loadAndShowConsentFormIfRequired(
        activity,
        formError -> {
          // Consent gathering process is complete.
        });  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.java#L106-L113

### Kotlin


    UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity) { formError ->
      // Consent gathering process is complete.
    }  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.kt#L98-L103

## Privacy options

Some privacy message forms are presented from a publisher-rendered privacy
options entry point, letting users manage their privacy options at any time.
To learn more about which message your users see at the privacy options
entry point, see

[Available user message types](https://support.google.com/admob/answer/10114020).


### Check if a privacy options entry point is required

After you have called `
`[requestConsentInfoUpdate()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#public-abstract-void-requestconsentinfoupdate-activity-activity,-consentrequestparameters-consentrequestparameters,-consentinformation.onconsentinfoupdatesuccesslistener-successlistener,-consentinformation.onconsentinfoupdatefailurelistener-failurelistener), check `
`[getPrivacyOptionsRequirementStatus()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#getPrivacyOptionsRequirementStatus()) to
determine if a privacy options entry point is required for your app. If an entry
point is required, add a visible and interactable UI element to your app that
presents the privacy options form. If a privacy entry point is not required,
configure your UI element to be not visible and interactable.  

### Java


    /** Helper variable to determine if the privacy options form is required. */
    public boolean isPrivacyOptionsRequired() {
      return consentInformation.getPrivacyOptionsRequirementStatus()
          == PrivacyOptionsRequirementStatus.REQUIRED;
    }  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.java#L63-L68

### Kotlin


    /** Helper variable to determine if the privacy options form is required. */
    val isPrivacyOptionsRequired: Boolean
      get() =
        consentInformation.privacyOptionsRequirementStatus ==
          ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.kt#L47-L52

For the full list of privacy options requirement statuses, see
`
`[ConsentInformation.PrivacyOptionsRequirementStatus](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation.PrivacyOptionsRequirementStatus).

### Present the privacy options form

When the user interacts with your element, present the privacy options form:  

### Java


    UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener);  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.java#L121-L121

### Kotlin


    UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener)  
    https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/GoogleMobileAdsConsentManager.kt#L113-L113

<br />

## Request ads with user consent

Before requesting ads, use `
`[canRequestAds()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#canRequestAds()) to check if you've
obtained consent from the user:  

### Java

    consentInformation.canRequestAds();

### Kotlin

    consentInformation.canRequestAds()

Listed are the following places to check if you can request ads while gathering
consent:

- After the UMP SDK gathers consent in the current session.
- Immediately after you have called `
  `[requestConsentInfoUpdate()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#public-abstract-void-requestconsentinfoupdate-activity-activity,-consentrequestparameters-consentrequestparameters,-consentinformation.onconsentinfoupdatesuccesslistener-successlistener,-consentinformation.onconsentinfoupdatefailurelistener-failurelistener). The UMP SDK might have obtained consent in the previous app session.

| **Important:** `
| `[canRequestAds()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#canRequestAds()) always returns `false` until you have called `
| `[requestConsentInfoUpdate()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#public-abstract-void-requestconsentinfoupdate-activity-activity,-consentrequestparameters-consentrequestparameters,-consentinformation.onconsentinfoupdatesuccesslistener-successlistener,-consentinformation.onconsentinfoupdatefailurelistener-failurelistener)

If an error occurs during the consent gathering process, check if you can
request ads. The UMP SDK uses the consent status from the previous app session.

#### Prevent redundant ad request work

As you check `
`[canRequestAds()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#canRequestAds()) after gathering consent and after calling
`
`[requestConsentInfoUpdate()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#public-abstract-void-requestconsentinfoupdate-activity-activity,-consentrequestparameters-consentrequestparameters,-consentinformation.onconsentinfoupdatesuccesslistener-successlistener,-consentinformation.onconsentinfoupdatefailurelistener-failurelistener), ensure your logic prevents redundant ad requests that
might result in both checks returning `true`. For example, with a boolean
variable.

<br />

## Testing

If you want to test the integration in your app as you're developing, follow
these steps to programmatically register your test device. Be sure to remove the
code that sets these test device IDs before you release your app.
| **Note:** As of version 2.2.0, emulators don't need to be added to your device ID list as they are test devices by default.

1. Call `
   `[requestConsentInfoUpdate()](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentInformation#public-abstract-void-requestconsentinfoupdate-activity-activity,-consentrequestparameters-consentrequestparameters,-consentinformation.onconsentinfoupdatesuccesslistener-successlistener,-consentinformation.onconsentinfoupdatefailurelistener-failurelistener).
2. Check the log output for a message similar to the following example, which
   shows your device ID and how to add it as a test device:

       Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.

3. Copy your test device ID to your clipboard.

4. Modify your code to call
   `ConsentDebugSettings.Builder().TestDeviceHashedIds` and pass in
   a list of your test device IDs.

   ### Java

       ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this)
           .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
           .build();

       ConsentRequestParameters params = new ConsentRequestParameters
           .Builder()
           .setConsentDebugSettings(debugSettings)
           .build();

       consentInformation = UserMessagingPlatform.getConsentInformation(this);
       // Include the ConsentRequestParameters in your consent request.
       consentInformation.requestConsentInfoUpdate(
           this,
           params,
           // ...
       );

   ### Kotlin

       val debugSettings = ConsentDebugSettings.Builder(this)
           .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
           .build()

       val params = ConsentRequestParameters
           .Builder()
           .setConsentDebugSettings(debugSettings)
           .build()

       consentInformation = UserMessagingPlatform.getConsentInformation(this)
       // Include the ConsentRequestParameters in your consent request.
       consentInformation.requestConsentInfoUpdate(
           this,
           params,
           // ...
       )

### Force a geography

The UMP SDK provides a way to test your app's behavior as though the device
were located in various regions, such as the EEA or UK, using

[`setDebugGeography()`](https://developers.google.com/admob/android/privacy/api/reference/com/google/android/ump/ConsentDebugSettings.Builder.html#setDebugGeography(int)). Note that debug settings only work on test devices.  

### Java

    ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this)
        .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
        .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
        .build();

    ConsentRequestParameters params = new ConsentRequestParameters
        .Builder()
        .setConsentDebugSettings(debugSettings)
        .build();

    consentInformation = UserMessagingPlatform.getConsentInformation(this);
    // Include the ConsentRequestParameters in your consent request.
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        ...
    );

### Kotlin

    val debugSettings = ConsentDebugSettings.Builder(this)
        .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
        .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
        .build()

    val params = ConsentRequestParameters
        .Builder()
        .setConsentDebugSettings(debugSettings)
        .build()

    consentInformation = UserMessagingPlatform.getConsentInformation(this)
    // Include the ConsentRequestParameters in your consent request.
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        ...
    )

### Reset consent state

When testing your app with the UMP SDK, you might find it helpful to reset the
state of the SDK so that you can simulate a user's first install experience.
The SDK provides the `reset()` method to do this.  

### Java

    consentInformation.reset();

### Kotlin

    consentInformation.reset()

| **Caution:** This method is intended to be used for testing purposes only. You shouldn't call `reset()` in production code.

## Examples on GitHub

See a full example of the UMP SDK integration covered in this page in


[Java BannerExample](https://github.com/googleads/googleads-mobile-android-examples/tree/main/java/admob/BannerExample) and
[Kotlin BannerExample](https://github.com/googleads/googleads-mobile-android-examples/tree/main/kotlin/admob/BannerExample).