繁体   English   中英

无法加载admob ad errror:3 ERROR_CODE_NO_FILL

[英]Failed to load admob ad errror:3 ERROR_CODE_NO_FILL

我无法加载广告错误:3。

我已经尝试过请求欧洲用户的同意。但是它没有用,我已经等了7天了。

class MainActivity{
    lateinit var mAdView: AdView
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    getUserConsent()
    }

    @SuppressLint("HardwareIds")
    private fun getUserConsent() {
    try {
    if (!isConsentYet) {
    val msg = "Your privacy policy"

    @SuppressLint("InflateParams")
    val view = LayoutInflater.from(this@MainActivity)
                    .inflate(R.layout.dialog_consent, null, false)

    val d = AlertDialog.Builder(this)
                    .setView(view)
                    .setCancelable(false)
                    .setTitle("User Consent")
                    .setIcon(R.mipmap.ic_launcher)
                    .create()
    view.txtAlertMsg.text = Html.fromHtml(msg)
    view.btnAccept.setOnClickListener {

    ConsentInformation.getInstance(this@MainActivity).addTestDevice(
                        Settings.Secure.getString(
                            contentResolver,
                            Settings.Secure.ANDROID_ID
                        )
                    )

    ConsentInformation.getInstance(this@MainActivity).consentStatus =
                        if (view.chkGDPR.isChecked) 
    ConsentStatus.PERSONALIZED else ConsentStatus.NON_PERSONALIZED
                    isConsentYet = true
                    d.dismiss()
                    loadAds()
                }
                d.show()
                setTextViewHTML(view.txtAlertMsg, msg)
            } else {
                loadAds()
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }

    protected fun setTextViewHTML(text: TextView, html: String) {
        val sequence = Html.fromHtml(html)
        val strBuilder = SpannableStringBuilder(sequence)
        val urls = strBuilder.getSpans(0, sequence.length, 
    URLSpan::class.java)
        for (span in urls) {
            makeLinkClickable(strBuilder, span)
        }
        text.text = strBuilder
        text.movementMethod = LinkMovementMethod.getInstance()
    }

    protected fun makeLinkClickable(strBuilder: 
    SpannableStringBuilder, span: URLSpan) {
        val start = strBuilder.getSpanStart(span)
        val end = strBuilder.getSpanEnd(span)
        val flags = strBuilder.getSpanFlags(span)
        val clickable = object : ClickableSpan() {
            override fun onClick(view: View) {
                val i = Intent(Intent.ACTION_VIEW)
                i.data = Uri.parse("Privacy URL")
                startActivity(i)
            }
        }
        strBuilder.setSpan(clickable, start, end, flags)
        strBuilder.removeSpan(span)
    }

     private fun loadAds() {
        mAdView = findViewById(R.id.adView)
        MobileAds.initialize(this, getString(R.string.app_id))
        val adRequest = AdRequest.Builder().build()
        val adView = AdView(this)
        adView.adSize = AdSize.BANNER
        adView.adUnitId = getString(R.string.ad_bottom)
        mAdView.loadAd(adRequest)

        mAdView.adListener = object : AdListener() {
            override fun onAdLoaded() {
                // Code to be executed when an ad finishes loading.
                Log.w("AdListener", "onAdLoaded")
            }

            override fun onAdFailedToLoad(errorCode: Int) {
                // Code to be executed when an ad request fails.
                Log.w("AdListener", 
    "onAdFailedToLoad".plus(errorCode))
            }

            override fun onAdOpened() {
                // Code to be executed when an ad opens an overlay 
    that
                // covers the screen.
                Log.w("AdListener", "onAdOpened")
            }

            override fun onAdClicked() {
                // Code to be executed when the user clicks on an ad.
                Log.w("AdListener", "onAdClicked")
            }

            override fun onAdLeftApplication() {
                // Code to be executed when the user has left the app.
                Log.w("AdListener", "onAdLeftApplication")
            }

            override fun onAdClosed() {
                // Code to be executed when the user is about to 
    return
                // to the app after tapping on an ad.
                Log.w("AdListener", "onAdClosed")
            }
       }
}

总是,我在几天内收到了ERROR_CODE_NO_FILL。

谷歌解释

ERROR_CODE_NO_FILL广告请求已成功,但由于缺少广告资源,未返回任何广告。

但是,如果您能够看到测试广告,那么您的代码就没有任何问题。 可能谷歌支持可以帮助你,他们会要求你的AdsUnitId和appId进行测试并回答你的真正问题。 这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM