【问题标题】:Sometime AdMob Banner and interstitial does not load有时 AdMob 横幅和插页式广告无法加载
【发布时间】:2018-04-25 19:34:09
【问题描述】:

我在 google play 上有一个金融应用程序,我每天在应用程序中有 800 个活跃用户。有时 AdMob 横幅和 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();
    }


}

【问题讨论】:

    标签: android admob


    【解决方案1】:

    这是因为两个原因,

    1. 网络需要一些时间来加载 AD,因为它在活动打开时被请求。 要解决此问题,您必须在应用启动时预加载广告,并请求在您需要显示此内容的特定活动上显示。
    2. 这还取决于互联网连接。由于互联网连接,会有一些延迟。

    【讨论】:

    • 不,我有 wifi 连接。
    • 即使您正在使用 Wi-Fi 连接,加载广告的请求和响应时间也需要一些时间。所以预加载广告并调用活动之间的转换。你可以关注这个stackoverflow.com/questions/29304697/…
    • 如何预加载广告?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多