简体   繁体   中英

Failed to load admob ad errror:3 ERROR_CODE_NO_FILL

I have getting Failed to load ad error:3.

I have already tried with Requesting Consent from European Users.But It's not working, already I am waiting for 7 days.

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")
            }
       }
}

Always,I have getting ERROR_CODE_NO_FILL in few days.

Google explaination

ERROR_CODE_NO_FILL The ad request was successful, but no ad was returned due to lack of ad inventory.

But if you able to see test ads, there no problem with your code. Probably google support could help you, they will asking your AdsUnitId and appId to be tested and answer your true problem. Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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