אופטימיזציה ל-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 כדי לטפל בהפעלת המודעה סביב תמונת ה-fallback של סמל ה-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;