เราขอแนะนําแนวทางปฏิบัติแนะนำหลายประการเพื่อให้แอปทํางานอย่างถูกต้องบน 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;