为什么我的插页式广告在 andorid kotlin 中没有显示

问题描述 投票:0回答:1

**我尝试了很多次,但都失败了。我是 Android 开发新手。我的代码正确吗?请帮我。我创建了一个类来加载广告加载工作:**


class InterstitialAds {


    var mInterstitialAd: InterstitialAd? = null


     fun interAds(context: Context){

        MobileAds.initialize(context)


        var adRequest = AdRequest.Builder().build()

        InterstitialAd.load(context,"ca-app-pub-3940256099942544/1033173712", adRequest, object : InterstitialAdLoadCallback() {

            override fun onAdFailedToLoad(adError: LoadAdError) {
                adError?.toString()?.let { Log.d(ContentValues.TAG, it) }
                mInterstitialAd = null
            }

            override fun onAdLoaded(interstitialAd: InterstitialAd) {
                mInterstitialAd = interstitialAd

            }
        })
    }
}

** 在适配器中: **

holder.thumbnail.setOnClickListener {


            val interstitialAds = InterstitialAds()
            interstitialAds.interAds(context)


            if (interstitialAds.mInterstitialAd != null) {
                interstitialAds.mInterstitialAd!!.show(context as Activity)
                interstitialAds.mInterstitialAd!!.fullScreenContentCallback =
                    object : FullScreenContentCallback() {

                        override fun onAdDismissedFullScreenContent() {
                            // Called when ad is dismissed.
                            interstitialAds.mInterstitialAd = null
                            interstitialAds.interAds(context)
                            progressBar.visibility = View.VISIBLE
                            webView.visibility = View.VISIBLE
                            thumnail.visibility = View.GONE

                            val webSettings: WebSettings = webView.settings
                            webSettings.javaScriptEnabled = true


                            webView.webViewClient = object : WebViewClient() {
                                override fun onPageFinished(view: WebView?, url: String?) {
    
                                    progressBar.visibility = View.GONE
                                    fullButton.visibility = View.VISIBLE

                                }
                            }

                            webView.loadData(item.videoEmbed!!, "text/html", "utf-8")


                        }

                    }
                
            }

**任何人都可以帮我解决这个问题吗?我的代码正确吗?请帮我。我创建了一个类来加载广告加载工作**

android kotlin error-handling ads interstitial
1个回答
0
投票

如果您的应用程序处于生产阶段,请使用

RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("455FDC94B1F5B4415BD853EEB4FFCDB0"))

之前

MobileAds.initialize(context)

如果您不知道 TestDeviceId,请在 logcat 中搜索 safeDK Device ID

如果这不起作用,请更改您的包名称以进行测试。并在发布新更新之前将其更改回来

© www.soinside.com 2019 - 2024. All rights reserved.