<br />

The Google Mobile Ads SDK supports monetizing your apps with an [Ad Exchange
property](https://support.google.com/admanager/answer/6321605). This guide shows you
how to configure your apps for all ad formats supported by Ad Exchange.

## Prerequisites

- [Complete the
  prerequisites](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start#app_prerequisites).
- [Configure your
  app](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start#import_the_mobile_ads_sdk) for the Google Mobile Ads SDK.

## Configure your app for accessing Ad Exchange

Add your Ad Manager app ID ([identified in the Ad Manager
UI](https://support.google.com/admanager/answer/1656921)) to your app's
AndroidManifest.xml file through a `<meta-data>` tag with
`android:name="com.google.android.gms.ads.APPLICATION_ID"`. For `android:value`,
insert your own Ad Manager app ID, surrounded by quotation marks.

```xml
<manifest>
    <application>
        <!-- Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>
```

Note also that failure to add the `<meta-data>` tag as shown above results in a
crash with the message:

    Missing application ID.

Next, you can [initialize the Google Mobile Ads
SDK](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start#initialize_the_mobile_ads_sdk)
and select an ad format to display. The rest of this guide implements the
[banner format](https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner.md.txt) to
illustrate how you can load an ad from Ad Exchange. The same steps can apply to
any ad formats supported by the Google Mobile Ads SDK.


## Load an ad from Ad Exchange

You can use an Ad Exchange web property code with a trailing forward slash, in
place of an ad unit ID. For example, `ca-mb-app-pub-5629679302779023/`.

For example, to load a banner ad by placing an `AdManagerAdView` in the layout
for the `Activity` as follow:

```xml
# main_activity.xml
...
  <com.google.android.gms.ads.admanager.AdManagerAdView
      xmlns:ads="http://schemas.android.com/apk/res-auto"
      android:id="@+id/adManagerAdView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_alignParentBottom="true"
      ads:adSize="BANNER"
      ads:adUnitId="ca-mb-app-pub-5629679302779023/">
  </com.google.android.gms.ads.admanager.AdManagerAdView>
```

> [!IMPORTANT]
> **Key Point:** Make sure you set the ad size and ad unit ID in the same manner, that is, set both in XML or both programmatically.


Alternatively, you can create a view hierarchy programmatically:

### Java

```java
AdManagerAdView adView = new AdManagerAdView(this);

adView.setAdSizes(AdSize.BANNER);
adView.setAdUnitId("ca-mb-app-pub-5629679302779023/");

// TODO: Add adView to your view hierarchy.
```

### Kotlin

```kotlin
val adView = AdManagerAdView(this)

adView.adSizes = AdSize.BANNER
adView.adUnitId = "ca-mb-app-pub-5629679302779023/"

// TODO: Add adView to your view hierarchy.
```

Once the `AdManagerAdView` is in place, you can [call the `loadAd()`
method](https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner#load_an_ad) in the
`AdManagerAdView` class and customize the behavior of your ad using [ad
events](https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner#ad_events).

Note that failure to add a trailing forward slash to the Ad Exchange web
property code results in an ad request error with the message:

    Invalid Request. Cannot determine request type. Is your ad unit id correct?

You can also convert an Ad Exchange web property code into an ad unit.
Afterwards, use the Ad Manager UI to [generate an Ad Exchange
Tag](https://support.google.com/admanager/answer/7501422) and copy it into your
app. The generated tag should have the Ad Exchange web property code, followed
by descendant ad unit IDs without a trailing forward slash, for example:
`ca-mb-app-pub-5629679302779023/banner`.

That's it! Your app is now ready to load and display banner ads from Ad Exchange.

In addition, you can use an Ad Exchange web property to load and display other
ad formats from Ad Exchange by following respective guides:

- [Interstitial](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start.md.txt#interstitial)
- [Native](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start.md.txt#native)
- [Rewarded](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start.md.txt#rewarded)

## (Approved European publishers only) Add price floors

You can [submit a request for the "Price floors"
feature](https://support.google.com/admanager/answer/7501422#submit-request).

Once approved, you can include a public floor or private floor in the ad request
using the `pubf` and `pvtf` parameters respectively. In the following code
example, replace "123" with the floor prices in micros and your [network's
default currency](https://support.google.com/admanager/answer/177495). Example of how
micros are applied: if your default currency is USD, entering "6000000" is the
equivalent of $6.00.

### Java

```java
Bundle extras = new Bundle();
// Public floor parameter.
extras.putString("pubf", "123");
// Private floor parameter.
extras.putString("pvtf", "123");

AdManagerAdRequest request = new AdManagerAdRequest.Builder()
    .addNetworkExtrasBundle(AdMobAdapter.class, extras)
    .build();
```

### Kotlin

```kotlin
val extras = Bundle();
// Public floor parameter.
extras.putString("pubf", "123");
// Private floor parameter.
extras.putString("pvtf", "123");

val request = AdManagerAdRequest.Builder()
    .addNetworkExtrasBundle(AdMobAdapter::class::java, extras)
    .build();
```