Android应用不会展示广告

时间:2018-04-18 17:26:36

标签: android admob

广告不起作用..

在日志中

I/Ads: Starting ad request.
I/Ads: This request is sent from a test device.

但是在app toast“广告没有加载”

Ads.class

public class Ads extends AppCompatActivity {
PublisherInterstitialAd mPublisherInterstitialAd;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mPublisherInterstitialAd = new PublisherInterstitialAd(this);
    mPublisherInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));

    mPublisherInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            requestNewInterstitial();
            startActivity(new Intent(Ads.this, MainActivity.class));

        }
    });
    requestNewInterstitial();
    showInterstitial();

}

private void requestNewInterstitial() {
    PublisherAdRequest adRequest = new PublisherAdRequest.Builder()
            .addTestDevice("XXXXXXXXXXXXXXX").build();

    mPublisherInterstitialAd.loadAd(adRequest);
}
public void showInterstitial() {
    // Show the ad if it's ready. Otherwise toast and reload the ad.
    if (mPublisherInterstitialAd != null && mPublisherInterstitialAd.isLoaded()) {
        mPublisherInterstitialAd.show();
    } else {
        Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(Ads.this, MainActivity.class));
    }
}
}

我尝试了一切,甚至在AdMob中创建了一个新的ID, 但仍然无法正常工作.. 刚在真实的设备上试过..

为什么?

1 个答案:

答案 0 :(得分:0)

要了解具体问题,请在AdFailedToLoad中实施AdListner覆盖方法 并捕获错误代码。

Here,然后您可以映射错误代码的含义并更好地理解您的问题。