Search code examples
androidandroid-layoutadmobinterstitial

Ad network not displaying android?


Hi I am using admob to display ads. But when I use, it's not displaying the ads. I checked two to three times in admob by verifying interstitial ad id and applied. Even created another id and checked but it;s not displaying. I am clueless what line I am missing to display.

public class MainActivity extends AppCompatActivity {
    private InterstitialAd mInterstitialAd;
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-6918701967372612/2472865080");
 AdRequest adRequests = new AdRequest.Builder().build();
        mInterstitialAd.loadAd(adRequests);
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                super.onAdLoaded();
                mInterstitialAd.show();

            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                super.onAdFailedToLoad(errorCode);

            }

enter image description here


Solution

  • @Shadow

    Ad will never display unless and until you run test Ad on that Ad View. Create your ad request like -

    AdRequest adRequest = new AdRequest.Builder()
     //Add a test device to show Test Ads
         .addTestDevice("4CCC00EF4EA205A6FE82E1AEB26B0839")
         .build();
    
        //Load ads into Banner Ads
        adView.loadAd(adRequest);
    

    Once the test ad is shown then you can remove addTestDevice line .addTestDevice("4CCC00EF4EA205A6FE82E1AEB26B0839")

    And then again run your application. Real ad will be shown. I think google has now forced this way of ads implementation. I also faced a lot of problem initially but after sometime i identified this behaviour.