【发布时间】: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