Android TV 向けに最適化する

IMA SDK for Android を使用して Android TV でアプリが適切に機能するようにするには、いくつかのベスト プラクティスをおすすめします。

まず、 Android 向けの TV アプリの開発について理解してください特に、スタートガイドの説明に沿って、アクティビティが TV 向けに設定されていることを確認してください。また、 TV ナビゲーションを処理して、 ユーザーが Android TV でアプリを適切に操作できるようにする必要があります。

スキップ可能な広告を処理する

SDK は、TV のようなデバイス向けにスキップ可能なフォーマットを最適化します。たとえば、[詳細] ボタンを操作できないようにします。デフォルトでは、スキップが可能な場合、SDK はスキップボタンにフォーカスを設定するため、Android TV で広告をスキップできます。そのため、スキップ可能な広告をサポートするために特別な作業は必要ありません。

これは、 AdsRenderingSettings.setFocusSkipButtonWhenAvailable() を呼び出すことで構成できます。

サポートされている広告について詳しくは、 互換性マトリックスをご覧ください。

VAST アイコンのフォールバック画像を処理する

IMA SDK は、VAST アイコンのフォールバック画像を検出し、レンダリングして、ユーザーの操作を処理します。アプリは、[この広告が表示された理由](WTA)を使用する広告の広告再生を処理するために、ICON_TAPPED イベントと ICON_FALLBACK_IMAGE_CLOSED イベントをリッスンする必要があります。

VAST アイコンのフォールバック画像が表示されているかどうかを追跡するブール値を追加します。次に、ICON_TAPPEDICON_FALLBACK_IMAGE_CLOSED をリッスンして、VAST アイコンのフォールバック画像に関する広告再生を処理します。高度なサンプル でこの処理を行う方法の例については、 次のコード スニペットをご覧ください。

VideoPlayerController.java

// Copyright 2014 Google Inc. All Rights Reserved.

package com.google.ads.interactivemedia.v3.samples.videoplayerapp;

import android.app.UiModeManager;
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;

...

    adsManager.addAdEventListener(
        new AdEvent.AdEventListener() {
          /** Responds to AdEvents. */
          @Override
          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.
                resumeContent();
                break;
              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.
                adsManager.focus();
                break;
              case PAUSED:
                if (isConnectedTvFallbackImageShowing) {
                  // Do not show the controls; continue to leave the controls in
                  // the hands of the ads SDK.
                  break;
                }
                isAdPlaying = false;
                videoPlayerWithAdPlayback.enableControls();
                break;
              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;
                adsManager.resume();
                break;
              case RESUMED:
                isAdPlaying = true;
                videoPlayerWithAdPlayback.disableControls();
                break;