Linked Questions

Popular Questions

Problem loading Test InterstitialAd - Ad failed loading error code 0

Asked by At

I signed up and copied the code written in the guide in incorporating Interstitial ads in my app. I'm able to load the ads only with the guide supplied ad unit id, but can't load it with my ad unit id. I tried both with and without add test device. If can you please tell me what i'm doing wrong i would much appreciate it. Thanks ahead Here's my code:

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-5072946366414238/8800518204");
    mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("B8BEF7C59DBDD2FFE49A5719CC4EC479").build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            // Code to be executed when an ad finishes loading.
            int a =5;
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            // Code to be executed when an ad request fails.
            int a =5;
        }

        @Override
        public void onAdOpened() {
            // Code to be executed when the ad is displayed.
        }

        @Override
        public void onAdLeftApplication() {
            // Code to be executed when the user has left the app.
        }

        @Override
        public void onAdClosed() {
            // Code to be executed when when the interstitial ad is closed.
        }
    });

    findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
            } else {
                mInterstitialAd.loadAd(new AdRequest.Builder().build());
            }
        }
    });
}

}

Related Questions