To test this feature and view the example code, please see the Android SDK 5 Example Code Quick Start guide.

This application inserts advertisements using the IMAWrapper class via the Google Interactive Media Ads (IMA) SDK to access ad servers that support VAST and VMAP. For more information, see:

Prerequisites

Advert server already configured and knowledge of the ad tag URLs that will be used to access it.

Example code

The Java source code contains the IMAWrapper package which simplifies configuration and access to an ad-server, as well as playback and display of the adverts. The following instructions show you how to modify your existing application to make use of the IMAWrapper package with the Google IMA libraries; the main stages are as follows:

  • Project setup
  • Enable playback of linear adverts (video sections interrupting playback)
  • Enable playback of companion adverts (views accompanying the main video)

Project setup

In the application project you are building, update your Gradle script to fetch the Google IMA Play Services libraries from the Google Maven repository.

  • Add the repository:
     repositories {
      jcenter()
      mavenCentral()
    
    ... << other repositories omitted >> ...
    
      maven {
        url "https://maven.google.com/"
      }
    }
    
     
  • Add the following third-party dependencies:
     ... <<details omitted >> ...
    
    dependencies {
      ... << other dependencies omitted >> ...
    
      implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.11.3'
      implementation 'com.google.android.gms:play-services-ads:18.0.0'
    }
    
     
  • To resolve conflicts in child dependencies, you will need a gradle.properties file:
     android.useAndroidX=true
    android.enableJetifier=true
    
     
Next step: Enable playback of linear adverts.