Android TV के साथ Android के लिए IMA SDK इस्तेमाल करना

Android के लिए IMA SDK का इस्तेमाल करते समय, आपका ऐप्लिकेशन Android TV पर ठीक से काम करे, यह पक्का करने के लिए हम कई सबसे सही तरीकों का सुझाव देते हैं.

Android के लिए टीवी ऐप्लिकेशन डेवलप करने के बारे में जानें. खास तौर पर, यह पक्का करें कि आपकी ऐक्टिविटी को टीवी के लिए सेट अप किया गया है, जैसा कि शुरुआती निर्देश में बताया गया है. टीवी नेविगेशन को भी हैंडल करें, ताकि उपयोगकर्ता आपके ऐप्लिकेशन को Android TV पर सही तरीके से नेविगेट कर पाएं.

स्किप किए जा सकने वाले विज्ञापनों को मैनेज करें

SDK टूल, टीवी जैसे डिवाइसों के लिए स्किप किए जा सकने वाले फ़ॉर्मैट को ऑप्टिमाइज़ करता है. उदाहरण के लिए, ज़्यादा जानें बटन से जुड़ने की सुविधा को हटाकर. डिफ़ॉल्ट रूप से SDK टूल, स्किप करने की सुविधा उपलब्ध होने पर स्किप बटन पर फ़ोकस सेट करता है, ताकि Android TV पर विज्ञापन को स्किप किया जा सके. इसलिए, स्किप किए जा सकने वाले विज्ञापनों को दिखाने के लिए कुछ और करने की ज़रूरत नहीं है.

AdsRenderingSettings.setFocusSkipButtonWhenAvailable() पर कॉल करके, इसे कॉन्फ़िगर किया जा सकता है.

किस तरह के विज्ञापन काम करते हैं, इस बारे में ज़्यादा जानने के लिए कम्पैटबिलटी मेट्रिक देखें.

VAST (वीडियो विज्ञापन देने के लिए टेम्प्लेट) आइकॉन फ़ॉलबैक इमेज को मैनेज करें

IMA SDK, VAST (वीडियो विज्ञापन देने के लिए टेम्प्लेट) आइकॉन फ़ॉलबैक इमेज का पता लगाता है, रेंडर करता है, और उपयोगकर्ता के इंटरैक्शन को मैनेज करता है. 'यह विज्ञापन क्यों' (WTA) का इस्तेमाल करने वाले विज्ञापनों को विज्ञापन दिखाने के लिए, आपके ऐप्लिकेशन को ICON_TAPPED और ICON_FALLBACK_IMAGE_CLOSED इवेंट को सुनना चाहिए.

कोई बूलियन जोड़कर ट्रैक करें कि VAST (वीडियो विज्ञापन देने के लिए टेम्प्लेट) आइकॉन फ़ॉलबैक इमेज दिख रही है या नहीं. इसके बाद, VAST (वीडियो विज्ञापन देने के लिए टेम्प्लेट) आइकॉन फ़ॉलबैक इमेज के आस-पास विज्ञापन चलाने के लिए, ICON_TAPPED और ICON_FALLBACK_IMAGE_CLOSED को सुनें. नीचे दिए गए कोड स्निपेट में बताया गया है कि बेहतर उदाहरण में, इसे कैसे मैनेज किया जाता है.

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;