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