android 全屏内容回调- onAddismissedFullScreenContent从未调用

uyhoqukh  于 2022-12-28  发布在  Android
关注(0)|答案(1)|浏览(166)
    • bounty将在5天后过期**。回答此问题可获得+100声望奖励。prom85希望引起更多人关注此问题。

我正在使用最新的广告播放服务(21.4.0),并看到以下行为(使用测试应用ID和测试广告ID进行测试):
FullScreenContentCallbackonAdDismissedFullScreenContent函数从未被调用。

    • 问题**

当我点击插播广告中的关闭按钮时,没有回调函数被调用......里面的所有其他函数(至少是非错误函数)都被成功调用。为什么?我错过了什么吗?我需要对广告被取消的事件做出React......

    • 代码**

1.加载广告

InterstitialAd.load(
    context,
    adId,
    AdRequest.Builder().build(),
    createInterstitialAdListener()
)

1.等待广告加载到侦听器中

private fun createInterstitialAdListener(): InterstitialAdLoadCallback {
    return object : InterstitialAdLoadCallback() {
        override fun onAdLoaded(ad: InterstitialAd) {
            super.onAdLoaded(ad)
            L.d { "Interstitial ad loaded..." }
            ad.fullScreenContentCallback = createFullScreenContentCallback("Interstitial")
            interstitialAd = ad
            this@AdsViewManager.onAdLoaded()
        }

        override fun onAdFailedToLoad(error: LoadAdError) {
            super.onAdFailedToLoad(error)
            onAdLoadingError(error.message)
        }
    }
}

private fun createFullScreenContentCallback(type: String): FullScreenContentCallback {
    return object : FullScreenContentCallback() {
        override fun onAdClicked() {
            // works!
            L.d { "[$type] FullScreen ad clicked" }
        }

        override fun onAdDismissedFullScreenContent() {
            // never gets called!
            L.d { "[$type] FullScreen ad dismissed" }
            interstitialAd = null
            rewardedAd = null
        }

        override fun onAdFailedToShowFullScreenContent(error: AdError) {
            onAdLoadingError(error.message)
            interstitialAd = null
            rewardedAd = null
        }

        override fun onAdImpression() {
            // works!
            L.d { "[$type] FullScreen ad - IMPRESSION" }
        }

        override fun onAdShowedFullScreenContent() {
            // works!
            L.d { "[$type] FullScreen ad showed..." }
        }
    }
}

1.当广告准备好时显示它

fun show() {
  if (interstitialAd == null) {
   L.e { "Interstitial ad not ready" }
  } else {
    interstitialAd?.show(activity)
    L.d { "Showing interstitial ad..." }
  }
}
    • 来自上述代码的日志**
Interstitial ad loaded...
Showing interstitial ad... 
[Interstitial] FullScreen ad showed... 
[Interstitial] FullScreen ad - IMPRESSION
// missing the close log... it never appears...
toe95027

toe950271#

在您的Activity中尝试这种方式

private var interstitialAd: InterstitialAd? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    createInterstitialAdListener()
}

您的loadAd函数

private fun createInterstitialAdListener(): InterstitialAdLoadCallback {
    return object : InterstitialAdLoadCallback() {
        override fun onAdLoaded(ad: InterstitialAd) {
            super.onAdLoaded(ad)
            L.d { "Interstitial ad loaded..." }
            interstitialAd = ad
            this@AdsViewManager.onAdLoaded()
        }

        override fun onAdFailedToLoad(error: LoadAdError) {
            super.onAdFailedToLoad(error)
            onAdLoadingError(error.message)
        }
    }
}

显示广告时,复制/粘贴以下内容...

fun show() {
    if (interstitialAd == null) {
        L.e { "Interstitial ad not ready" }
    } else {
        interstitialAd?.fullScreenContentCallback = fullScreenContentCallback
        interstitialAd?.show(activity)
        L.d { "Showing interstitial ad..." }
    }
}

private val fullScreenContentCallback = object : FullScreenContentCallback() {
        override fun onAdClicked() {
            // works!
            L.d { "[$type] FullScreen ad clicked" }
        }

        override fun onAdDismissedFullScreenContent() {
            // never gets called!
            L.d { "[$type] FullScreen ad dismissed" }
            interstitialAd = null
            rewardedAd = null
        }

        override fun onAdFailedToShowFullScreenContent(error: AdError) {
            onAdLoadingError(error.message)
            interstitialAd = null
            rewardedAd = null
        }

        override fun onAdImpression() {
            // works!
            L.d { "[$type] FullScreen ad - IMPRESSION" }
        }

        override fun onAdShowedFullScreenContent() {
            // works!
            L.d { "[$type] FullScreen ad showed..." }
        }
    }
}

它会像预期的那样工作。如果不工作,请告诉我

相关问题