เราขอแนะนำให้ใช้แนวทางปฏิบัติที่ดีที่สุดหลายๆ ข้อเพื่อดูแลให้แอปทำงานได้อย่างถูกต้องใน 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 ดูตัวอย่างวิธีจัดการในตัวอย่างขั้นสูงได้ที่ข้อมูลโค้ดต่อไปนี้
app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/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;