有时AdMob Banner和插页式广告无法加载

时间:2018-04-25 10:27:28

标签: android admob

我在Google Play上有财务申请,我在应用中每天有800名活跃用户。有些时候AdMob banner和interstitialAd没有加载,它会显示白色横幅代替广告。下面的Java代码:

 AdView adView = (AdView) findViewById(R.id.adView);
            AdRequest adRequest = new AdRequest.Builder()
                   .addTestDevice("CA626566A7B365501AE304BBA64A11D9")
                   .build();
            adView.loadAd(adRequest);

的test.xml

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id" />

AdsUtil.java //这是我的interstitialAd java类,当用户返回任何屏幕然后我调用showInterstitial();

public class AdsUtil {

    private InterstitialAd mInterstitialAd;
    private Context context;

    public AdsUtil(Context context){
        this.context=context;
        mInterstitialAd = newInterstitialAd();
        loadInterstitial();
    }

    private InterstitialAd newInterstitialAd() {
        InterstitialAd interstitialAd = new InterstitialAd(context);
        interstitialAd.setAdUnitId(context.getString(R.string.interstitial_ad_unit_id));

        interstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
//                mNextLevelButton.setEnabled(true);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
//                mNextLevelButton.setEnabled(true);
            }

            @Override
            public void onAdClosed() {
                // Proceed to the next level.
                goToNextLevel();
            }
        });
        return interstitialAd;
    }

    public void showInterstitial() {
        // Show the ad if it's ready. Otherwise toast and reload the ad.
        if(!Utility.getSharedPreferencesBoolean(context, Constant.isPrimeUser) && Constant.adsFlag ) {

            Constant.adsFlag=false;
            timerAds();


            if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
            } else {
                goToNextLevel();
            }

        }
    }

    private void loadInterstitial() {
        // Disable the next level button and load the ad.
//        mNextLevelButton.setEnabled(false);
        AdRequest adRequest = new AdRequest.Builder().build();
//                .setRequestAgent("android_studio:ad_template").build();
        mInterstitialAd.loadAd(adRequest);
    }

    private void goToNextLevel() {
        // Show the next level and reload the ad to prepare for the level after.
//        mLevelTextView.setText("Level " + (++mLevel));
        mInterstitialAd = newInterstitialAd();
        loadInterstitial();
    }

    private void timerAds(){
        new CountDownTimer(1000*10*1, 1000) {

            public void onTick(long millisUntilFinished) {

            }

            public void onFinish() {
                Constant.adsFlag=true;
            }
        }.start();
    }


}

1 个答案:

答案 0 :(得分:0)

这是因为有两个原因,

  1. 网络将花费时间加载AD,因为它是在活动打开时请求的。 要解决此问题,您必须在应用程序启动时预加载AD,并请求显示您需要显示此项的特定活动。
  2. 它还取决于互联网连接。由于互联网连接,会有一些延迟。