如何销毁admob的特定插页式广告?

时间:2018-07-20 14:47:41

标签: android admob

可以选择显示插页式广告,但不能像Native Ad Express一样销毁它。我想在用户点击广告后销毁该广告。清空对象无效,因为在用户返回到应用程序之后,广告仍会显示。

这是我当前在Kotlin中的代码:

fun loadInterstitialAdWithOdds(minOdd: Int, maxOdd: Int) {
        //max - min +1 ) + min
        val rand = Random().nextInt(maxOdd - minOdd + 1) + minOdd
        //Log.i("Ad clicked", "odd = "+rand.toString())
        val myOdd : Int = (minOdd + maxOdd / 2)
        if (rand == myOdd) {
            mInterstitialAd = InterstitialAd(context)
            mInterstitialAd?.adUnitId = context.getString(R.string.test_interstitial_admob_id)
            mInterstitialAd?.loadAd(AdRequest.Builder().build())
            mInterstitialAd?.adListener = object : AdListener() {

                override fun onAdLoaded() {
                    mInterstitialAdLoaded = true
                }

                override fun onAdLeftApplication() {
                    super.onAdLeftApplication()
                    Log.i("Ad clicked", "Ad clicked")
                    Thread(Runnable {
                        checkFraudlentActivity()
                    }).start()
                }
            }
        }
    }

fun showInterstitalAd(minOdd: Int = 0, maxOdd: Int = 0) {
        if (isInterstitalAdLoaded()) {
            mInterstitialAd?.show()
            mInterstitialAdLoaded = false
            mInterstitialAd = null
        }
        if (mInterstitialAd == null && minOdd != 0
                && maxOdd != 0 && ManageAds(context).getAdStatus()) {
            loadInterstitialAdWithOdds(minOdd, maxOdd)
        }
}

0 个答案:

没有答案