【问题标题】:Control the appearance of an interstitial ad控制插页式广告的外观
【发布时间】:2017-09-17 11:55:42
【问题描述】:

我有一个插页式广告的问题,它不会出现在游戏中间,但在玩家离开并重新进入时出现。有没有解决方案显示游戏中间。

private ZenGL zengl;
private static final String AD_UNIT_ID = "ca-app-pub-3940256099942544/6300978111";
private static final String IAD_UNIT_ID = "ca-app-pub-3940256099942544/1033173712";
protected AdView adView;
private InterstitialAd mInterstitialAd;
private boolean needAds = false;

public void onAdLoaded() {
    mInterstitialAd.show();
};

@Override
public void onResume() {
    if ( zengl != null )
        zengl.onResume();

    if (adView != null)
        adView.pause();

    if (mInterstitialAd.isLoaded() & (needAds==true)) {
        mInterstitialAd.show();
        needAds=false;
    }  
    super.onResume();
}

private void requestNewInterstitial() {
    AdRequest adRequest = new AdRequest.Builder()
    //  .addTestDevice("")
    .build();

    mInterstitialAd.loadAd(adRequest);
    needAds = true;
}

如何编辑这些代码以显示中期游戏广告?

【问题讨论】:

    标签: java android admob ads interstitial


    【解决方案1】:
    private void showAd(){
        new AsyncTask<Void, Void, Void>(){
    
            @Override
            protected Void doInBackground(Void... params) {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                return null;
            }
    
            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                } else {
                    Log.d("TAG", "The interstitial wasn't loaded yet.");
                }
            }
        }.execute();
    }
    

    此功能将在 3 秒后显示广告;)

    【讨论】:

      【解决方案2】:

      请参阅官方文档以放置广告。 https://developers.google.com/admob/android/interstitial

      如果您想在游戏中间显示广告,一种简单的方法是创建一个单独的线程,该线程在您的游戏开始时开始,并在每个固定时间间隔触发事件以显示来自线程。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多