加载测试InterstitialAd时出现问题-广告加载失败,错误代码为0

时间:2019-02-07 14:14:57

标签: android admob

我注册并复制了指南中编写的将非页内广告整合到我的应用中的代码。 我只能使用指南提供的广告单元ID加载广告,但不能使用我的广告单元ID加载广告。 我尝试了有无添加测试设备。 如果您能告诉我我在做什么错,我将不胜感激。 提前谢谢 这是我的代码:

公共类MainActivity扩展了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());
            }
        }
    });
}

}

0 个答案:

没有答案