שימוש ב-IMA SDK ל-Android עם Android TV

אנחנו ממליצים על כמה שיטות מומלצות שיבטיחו שהאפליקציה תפעל כמו שצריך ב-Android TV בזמן השימוש ב-IMA SDK ל-Android.

אפשר להתחיל עם פיתוח אפליקציות לטלוויזיה ל-Android. ספציפית, ודאו שהפעילות מוגדרת לטלוויזיה, כמו שמוסבר במדריך למתחילים. כדאי גם לטפל בניווט בטלוויזיה כדי לוודא שהמשתמשים יכולים לנווט באפליקציה כראוי ב-Android TV.

ניהול מודעות שניתן לדלג עליהן

ב-SDK מתבצעת אופטימיזציה של פורמטים שניתן לדלג עליהם במכשירים דמויי טלוויזיה. לדוגמה, על ידי הסרת האפשרות לבצע אינטראקציה באמצעות לחצן מידע נוסף. כברירת מחדל, ה-SDK מגדיר את המיקוד על לחצן הדילוג כשהדילוג זמין, כך שאפשר לדלג על המודעה ב-Android TV. לכן לא נדרשת עבודה נוספת כדי לתמוך במודעות שניתן לדלג עליהן.

כדי להגדיר זאת, מתקשרים אל AdsRenderingSettings.setFocusSkipButtonWhenAvailable().

למידע נוסף על המודעות הנתמכות, אפשר לעיין במטריצת התאימות.

טיפול בתמונות חלופיות של סמל VAST

ה-IMA SDK מזהה, מעבד ומטפל באינטראקציות של המשתמש עם תמונות הגיבוי של סמל VAST. האפליקציה שלך צריכה להאזין לאירועים ICON_TAPPED ו-ICON_FALLBACK_IMAGE_CLOSED כדי לטפל בהפעלת המודעות במקרה של מודעות שמשתמשות ב'למה דווקא מודעה זו?' (WTA).

יש להוסיף ערך בוליאני כדי לבדוק אם מוצגת תמונה חלופית של סמל VAST. לאחר מכן, מאזינים ל-ICON_TAPPED ול-ICON_FALLBACK_IMAGE_CLOSED כדי לטפל בהפעלה של מודעות מסביב לתמונת החלופה של סמל VAST. תוכלו לעיין בקטע הקוד הבא כדי לראות דוגמה לאופן הטיפול בו בקטע Advanced Example.

app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/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;