כדי לוודא שהאפליקציה פועלת בצורה תקינה ב-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. ראו את קטע הקוד הבא לדוגמה של אופן הטיפול בכך בדוגמה המתקדמת.
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;