赛后间隙

时间:2018-07-09 13:42:00

标签: android admob interstitial

我有这个Java,并且我需要在游戏完成后出现插页式广告。关键是我希望在吐司游戏完成时显示插页式横幅广告。我该怎么办?

    // 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();
}

1 个答案:

答案 0 :(得分:0)

好吧,只需注释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);

}