Use IMA SDK for Android with Android TV

We recommend several best practices to ensure your app functions properly on Android TV when using the IMA SDK for Android.

Get started by familiarizing yourself with developing TV apps for Android. Specifically, make sure your Activity is set up for TV as explained in the start guide. You also want to handle TV navigation to make sure users can navigate your app well on Android TV.

Handle skippable ads

The SDK optimizes skippable formats for TV-like devices, for instance by removing the ability to engage with a Learn More button. By default, the SDK sets focus on the skip button when skipping is available so the ad can be skipped on Android TV. Therefore, no extra work is necessary to support skippable ads.

You can configure this by calling AdsRenderingSettings.setFocusSkipButtonWhenAvailable().

For more information on what ads are supported, check out the compatibility matrix.

Handle VAST icon fallback images

The IMA SDK detects, renders and handles user's interaction with the VAST icon fallback images. Your app should listen to the ICON_TAPPED and ICON_FALLBACK_IMAGE_CLOSED events to handle ad playback for ads that use 'Why this ad' (WTA).

Add a boolean to track whether a VAST icon fallback image is showing. Then, listen to the ICON_TAPPED and ICON_FALLBACK_IMAGE_CLOSED to handle ad playback around the VAST icon fallback image. See the following code snippet for an example of how this is handled in the Advanced Example.


// Copyright 2014 Google Inc. All Rights Reserved.


import android.content.Context;


// Tracks if the SDK is playing an ad, since the SDK might not necessarily use
// the video player provided to play the video ad.
private boolean isAdPlaying;

// Tracks whether the SDK has a VAST icon fallback image showing.
private boolean isConnectedTvFallbackImageShowing = false;

// View that handles taps to toggle ad pause/resume during video playback.
private View playPauseToggle;

// View that we can write log messages to, to display in the UI.
private Logger log;


        new AdEvent.AdEventListener() {
          /** Responds to AdEvents. */
          public void onAdEvent(AdEvent adEvent) {


              case CONTENT_RESUME_REQUESTED:
                // AdEventType.CONTENT_RESUME_REQUESTED is fired when the ad is
                // completed and you should start playing your content.
              case ICON_TAPPED:
                // The user has tapped a VAST icon fallback image. On Android
                // mobile apps, the SDK will navigate to the landing page. On
                // Connected TV devices, the SDK will present a modal dialog
                // containing the VAST icon fallback image.

                // Check if the app is running on a TV device.
                UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
                if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
                  isConnectedTvFallbackImageShowing = true;

                // Focus the IMA WebView for easier access to ad UI elements.
              case PAUSED:
                if (isConnectedTvFallbackImageShowing) {
                  // Do not show the controls; continue to leave the controls in
                  // the hands of the ads SDK.
                isAdPlaying = false;
              case ICON_FALLBACK_IMAGE_CLOSED:
                // The user has closed the VAST icon fallback image. This may
                // be a good time to resume ad playback if the user is ready to
                // continue playing the ad. This event only fires for Connected
                // TV devices.

                isConnectedTvFallbackImageShowing = false;
              case RESUMED:
                isAdPlaying = true;