0

I am testing Ads in an Android app. I want a button to be shown when the ad is loaded, and then click on the button to show the ad.

My issue is that the ad is never loaded.

This is my code so far:

 MobileAds.initialize(getActivity(), "ca-app-pub-***"); mInterstitialAd = new InterstitialAd(getActivity()); mInterstitialAd.setAdUnitId("ca-app-pub-ca-app-pub-***"); mInterstitialAd.loadAd(new AdRequest.Builder().build()); btnOfertar.setVisibility(View.GONE); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdLoaded() { // Code to be executed when an ad finishes loading. Log.i("Ads", "onAdLoaded"); btnOfertar.setVisibility(View.VISIBLE); } }); 
1
  • You are not showing ad. You need to add mInterstitialAd.show(); on method onAdLoaded(), and edit your mInterstitialAd.setAdUnitId("ca-app-pub-ca-app-pub-***"); to mInterstitialAd.setAdUnitId("ca-app-pub-***");. Also, check LogCat for more info. Commented Feb 13, 2019 at 19:21

1 Answer 1

1

You should try the following:

mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdLoaded() { // Add this mInterstitialAd.show() Log.i("Ads", "onAdLoaded"); btnOfertar.setVisibility(View.VISIBLE); } }); 

Also, try using the dedicated test ad id that Google provides in the documentation: ca-app-pub-3940256099942544/1033173712. If this loads properly your code should be okay.

Your actual ad might take a while to show up depending on how many requests you're getting to show the ad. Also make sure that your AdMob's payment is set up correctly.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.