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