If you still need to implement the IMA SDK in your app, check out our Get
Started guide.
Add companion ads to your app
Create a ViewGroup to display your companion
Before requesting a companion, you need to create a space for it in your
layout. In your layout XML, add a ViewGroup element; this
example uses a LinearLayout. In a later step you'll pass a
reference to this element to your AdDisplayContainer.
If you're
integrating into the BasicExample app, add this to activity_my.xml below the videoPlayerContainer.
The next step is to build a CompanionAdSlot object, which is
then added to an ArrayList<CompanionAdSlot>.
AdDisplayContainer takes a list of companion ad slots so you can
display multiple companion ads at once. You will need to create an instance of
ImaSdkFactory to create the CompanionAdSlot.
Create a companion ad slot for each size of companion you intend to show in your app.
The IMA SDK populates the companion ad slot with any companions from the VAST response that
have dimensions matching the view's height and width. The IMA SDK also supports using
fluid sized companions.
Once you have created the companionAdSlots they needed to be added to the
AdsLoader. The following examples show how to do this depending on whether you
are using the
IMA Android BasicExample which uses the
Exoplayer-IMA extension,
or other IMA implementations that do not use the extension.
BasicExample
adsLoader = new ImaAdsLoader.Builder(this).setCompanionAdSlots(companionAdSlots).build();
That's all there is to it! Your application is now displaying companion
ads.
Display fluid companion ads
IMA now supports fluid companion ads. These companions ads can resize to match the size of the ad
slot. They fill 100% of the width of parent view, then resize their height to fit the companion's
content. They're set by using the Fluid companion size in Ad Manager. See the
following image for where to set this value.
I followed the guide, but I'm not seeing companion ads. What should I do?
First, check to make sure your tag really is returning companions. To do
this, open the tag in a web browser and look for a CompanionAds tag. If you see
that, check to make sure the size of the companion being returned is the same
size as the dimensions you're passing into the CompanionAdSlot
object.
What will my companion ad slot look like when following this guide?
The image below was created from the
BasicExample
and has the content video playing above with the companion ad below.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-05 UTC."],[[["\u003cp\u003eThis guide helps publishers integrate companion ads into their Android applications using the IMA SDK.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers need an Android app with the IMA SDK and an ad tag configured to return companion ads to begin.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves creating a ViewGroup in the layout, a CompanionAdSlot object, and adding it to the AdsLoader.\u003c/p\u003e\n"],["\u003cp\u003eThe IMA SDK supports fluid companion ads that resize to fit the ad slot using \u003ccode\u003eCompanionAdSlot.FLUID_SIZE\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTroubleshooting tips are provided for common issues, such as not seeing companion ads after implementation.\u003c/p\u003e\n"]]],[],null,["Select platform: [HTML5](/interactive-media-ads/docs/sdks/html5/client-side/companions \"View this page for the HTML5 platform docs.\") [Android](/interactive-media-ads/docs/sdks/android/client-side/companions \"View this page for the Android platform docs.\") [iOS](/interactive-media-ads/docs/sdks/ios/client-side/companions \"View this page for the iOS platform docs.\")\n\nThis guide is intended for publishers interested in adding companion ads to\ntheir Android IMA implementation.\n\nPrerequisites\n\n- Android application with the IMA SDK integrated. See the [BasicExample](https://github.com/googleads/googleads-ima-android/blob/main/basicexample/) if you don't already have an app with the SDK integrated.\n- An ad tag configured to return a companion ad.\n - If you need a sample, check out our [FAQ](/interactive-media-ads/faq#4).\n\nHelpful primers\n\nIf you still need to implement the IMA SDK in your app, check out our [Get\nStarted guide](/interactive-media-ads/docs/sdks/android/client-side/quickstart).\n\nAdd companion ads to your app\n\nCreate a ViewGroup to display your companion\n\nBefore requesting a companion, you need to create a space for it in your\nlayout. In your layout XML, add a `ViewGroup` element; this\nexample uses a `LinearLayout`. In a later step you'll pass a\nreference to this element to your `AdDisplayContainer`.\n\nIf you're\nintegrating into the BasicExample app, add this to [`activity_my.xml`](https://github.com/googleads/googleads-ima-android/blob/main/basicexample/app/src/main/res/layout/activity_my.xml) below the `videoPlayerContainer`.\n\nactivity_my.xml \n\n```scdoc\n\u003cLinearLayout\n android:id=\"@+id/companionAdSlot\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"250dp\"\n android:layout_gravity=\"center_horizontal\"\n android:gravity=\"center\"\n android:orientation=\"vertical\"\n android:textAlignment=\"center\" /\u003e\n```\n\nCreate a CompanionAdSlot\n\nThe next step is to build a `CompanionAdSlot` object, which is\nthen added to an `ArrayList\u003cCompanionAdSlot\u003e`.\n`AdDisplayContainer` takes a list of companion ad slots so you can\ndisplay multiple companion ads at once. You will need to create an instance of\n`ImaSdkFactory` to create the `CompanionAdSlot`. \n\n```text\n ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();\n ViewGroup companionViewGroup = (ViewGroup) findViewById(R.id.companionAdSlot);\n\n CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();\n companionAdSlot.setContainer(companionViewGroup);\n companionAdSlot.setSize(300, 250);\n ArrayList\u003cCompanionAdSlot\u003e companionAdSlots = new ArrayList\u003cCompanionAdSlot\u003e();\n companionAdSlots.add(companionAdSlot);\n```\n\nCreate a companion ad slot for each size of companion you intend to show in your app.\nThe IMA SDK populates the companion ad slot with any companions from the VAST response that\nhave dimensions matching the view's height and width. The IMA SDK also supports using\n[fluid sized companions](/interactive-media-ads/docs/sdks/android/client-side/companions#display-fluid-companion-ads).\nOnce you have created the `companionAdSlots` they needed to be added to the\n`AdsLoader`. The following examples show how to do this depending on whether you\nare using the\n[IMA Android BasicExample](https://github.com/googleads/googleads-ima-android/blob/main/basicexample/) which uses the\n[Exoplayer-IMA extension](//github.com/google/ExoPlayer/tree/release-v2/extensions/ima),\nor other IMA implementations that do not use the extension. \n\nBasicExample \n\n```text\nadsLoader = new ImaAdsLoader.Builder(this).setCompanionAdSlots(companionAdSlots).build();\n```\n\nOther implementations \n\n```text\nadsLoader.getAdDisplayContainer().setCompanionSlots(companionAdSlots);\n```\n\nThat's all there is to it! Your application is now displaying companion\nads.\n\nDisplay fluid companion ads\n\nIMA now supports fluid companion ads. These companions ads can resize to match the size of the ad\nslot. They fill 100% of the width of parent view, then resize their height to fit the companion's\ncontent. They're set by using the `Fluid` companion size in Ad Manager. See the\nfollowing image for where to set this value.\n\nUpdate Android apps for fluid companions\n\nYou can declare a fluid companion slot by updating the\n[`CompanionAdSlot.setSize()`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/CompanionAdSlot#public-abstract-void-setsize-int-width,-int-height)\nmethod to take [`CompanionAdSlot.FLUID_SIZE`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/CompanionAdSlot#public-static-final-int-fluid_size)\nas both parameters. \n\n```scdoc\n ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();\n ViewGroup companionViewGroup = (ViewGroup) findViewById(R.id.companionAdSlot);\n\n CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();\n companionAdSlot.setContainer(companionViewGroup);\n companionAdSlot.setSize(CompanionAdSlot.FLUID_SIZE, CompanionAdSlot.FLUID_SIZE);\n ArrayList\u003cCompanionAdSlot\u003e companionAdSlots = new ArrayList\u003cCompanionAdSlot\u003e();\n companionAdSlots.add(companionAdSlot);\n```\n\nFAQ\n\nI followed the guide, but I'm not seeing companion ads. What should I do?\n: First, check to make sure your tag really is returning companions. To do\n this, open the tag in a web browser and look for a CompanionAds tag. If you see\n that, check to make sure the size of the companion being returned is the same\n size as the dimensions you're passing into the `CompanionAdSlot`\n object.\n\nWhat will my companion ad slot look like when following this guide?\n:\n The image below was created from the [BasicExample](https://github.com/googleads/googleads-ima-android/blob/main/basicexample/) and has the content video playing above with the companion ad below.\n\n \u003cbr /\u003e"]]