【问题标题】:Interstial after game complete游戏完成后的插播式
【发布时间】:2018-07-09 13:41:59
【问题描述】:

我有这个 java,我需要在游戏完成后出现插页式广告。关键是我希望在 toast Game Complete 出现时出现插页式横幅。我该怎么做?

    // Loading banner ads
    MobileAds.initialize(getActivity().getApplicationContext(), getResources().getString(R.string.banner_ad_unit_id));
    AdView mAdView = (AdView) v.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    mInterstitialAd = new InterstitialAd(getActivity());
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            // Code to be executed when an ad finishes loading.
            if (mInterstitialAd.isLoaded()){
                mInterstitialAd.show();
            }
        }
    });
    initViewId(v);


public void onGameComplete() {
    if (mMahjongListener != null) {
        mMahjongListener.onGameComplete();
    }
    mCompleted = true;
    Toast.makeText(getActivity(), this.getString(R.string.game), Toast.LENGTH_SHORT).show();
    ContentValues cv = new ContentValues();
    cv.put(MahjongContract.Mahjong.COL_COMPLETE, true);
    cv.put(MahjongContract.Mahjong.COL_CURRENT, (String) null);
    getActivity().getContentResolver().update(ContentUris.withAppendedId(MahjongContract.Mahjong.CONTENT_URI, mPuzzleId), cv, null,
            null);

}

public void onGameIncompletable() {
    if (mMahjongListener != null) {
        mMahjongListener.onGameIncompletable();
    }
    Toast.makeText(getActivity(), this.getString(R.string.solution), Toast.LENGTH_SHORT).show();
    resetPuzzle();
}

【问题讨论】:

  • Toast.LENGTH_SHORT 的持续时间约为 2 秒,因此当您在启动延迟处理程序后开始敬酒以显示插页式广告时。喜欢final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { //Do something after 2 second } }, 2000);
  • 但它没有出现在消息之后。我该怎么做?
  • 你试过 ` if (mInterstitialAd.isLoaded()){ mInterstitialAd.show(); }` 在处理程序运行方法中?,并在方法onGameComplete 的底部编写处理程序代码
  • 不要。我很新,不知道怎么说。
  • 好的,只需评论mInterstitialAd.setAdListener 代码并在onGameComplete() 中添加if (mInterstitialAd.isLoaded()){ mInterstitialAd.show(); } 并尝试。

标签: android admob interstitial


【解决方案1】:

好的,只需注释 mInterstitialAd.setAdListener 代码并替换 onGameComplete(),如下所示

public void onGameComplete() {
    if (mMahjongListener != null) {
        mMahjongListener.onGameComplete();
    }
    mCompleted = true;
    Toast.makeText(getActivity(), this.getString(R.string.game), Toast.LENGTH_SHORT).show();
    ContentValues cv = new ContentValues();
    cv.put(MahjongContract.Mahjong.COL_COMPLETE, true);
    cv.put(MahjongContract.Mahjong.COL_CURRENT, (String) null);
    getActivity().getContentResolver().update(ContentUris.withAppendedId(MahjongContract.Mahjong.CONTENT_URI, mPuzzleId), cv, null,
            null);


    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            if (mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
            }
        }
    }, 2000);

}

【讨论】:

  • 我会建议你不要放 Handler 否则会违反 admob 政策。
猜你喜欢
  • 1970-01-01
  • 2021-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多