Skip to main content
Skip table of contents

Enabling companion adverts

Companion adverts can be added if the screen layout and real estate of the application allow them. Multiple differently sized slots can be set aside for companion adverts to appear in. The dimensions selected depend on the style of companion adverts that you want to display. In the following examples, more than one configuration is shown and provided as a List of IMAWrapperCompanionAdContainer objects. An instance of one of these objects is created by providing a pair of integers for the dimensions and a reference to the ViewGroup.

There maybe subtle differences in how the application is organised, so there are alternatives for how companion adverts are configured and enabled, but in both cases you provide a List of IMAWrapperCompanionAdContainer objects, just at different points.

This procedure assumes you have already enabled linear ads, as described above.

  1. Generate companion ad list.

    JAVA
    ViewGroup companionAdPlaceholder = (ViewGroup) findViewById(R.id.companionAdSlot);
    ViewGroup anotherCompanionAdPlaceholder = (ViewGroup) findViewById(R.id.anotherCompanionAdSlot);
    
    List<IMAWrapper.IMAWrapperCompanionAdContainer> companionList = new ArrayList<IMAWrapper.IMAWrapperCompanionAdContainer>();
    
    companionList.add(new IMAWrapper.IMAWrapperCompanionAdContainer(
        new Pair<Integer, Integer>(300, 250), companionAdPlaceholder));
    
    companionList.add(new IMAWrapper.IMAWrapperCompanionAdContainer(
        new Pair<Integer, Integer>(728, 90), anotherCompanionAdPlaceholder));
    
    
  2. Edit the layout XML to support companion ads.
    The following example provides a pair of companion advert slots with different dimensions to accommodate different companion advert sizes. The number and dimensions of slots provided will depend on the style of adverts required to be shown and the available screen real estate.

    References to these slots and their dimensions must be provided to the IMAWrapper in order to enable companion adverts.

    XML
    <LinearLayout
        android:id="@+id/companionAdSlot"
        android:layout_width="300px"
        android:layout_height="250px"
        android:background="@android:color/transparent"
        android:gravity="center"
        android:orientation="horizontal"
        android:visibility="gone"/>
    
    <LinearLayout
        android:id="@+id/anotherCompanionAdSlot"
        android:layout_width="728px"
        android:layout_height="90px"
        android:background="@android:color/transparent"
        android:gravity="center"
        android:orientation="horizontal"
        android:visibility="gone"/>
  3. Set up the companion ads.

    • Simple case: overlay.
      In a simple application, the activity layout could be the video view and companion ad slots are configured together such that the video is overlaid with a companion advert when one is rendered.
      In this case, the IMAWrapper allows for the linear advert overlay and companion adverts to be configured in one go. The List can be provided to the IMAWrapper at the same time as the linear adverts ViewGroup in the call to startAdsServices():

      JAVA
      mIMAWrapper.startAdsServices(adUiContainerViewGroup, companionList);
    • More complex case: activity fragments.
      A more complex application may have activity fragments that are put together to form the overall user experience.
      Here, it may be more complicated to configure the companion advert placeholders and the main video advert overlay together, so the IMAWrapper allows for this to be enabled separately with a later call to setCompanionAdViews():

      JAVA
      mIMAWrapper.setCompanionAdViews(companionList);
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.