我只是像铁裤一样制作游戏,我试图在游戏结束时放置插页式广告。
但插页式广告总是显示在游戏中间。我认为这对用户来说会很烦人。我担心如果谷歌会禁止我的 admob 帐户。
插页式广告仅在 5 次游戏结束后显示。
我只有一个屏幕 MainGameView.java
这是游戏结束时显示 admob 插页式广告的代码
初始化插页式广告的方法
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialiseAccelerometer();
// Create the interstitial
interstitial = new InterstitialAd(this, getResources().getString(R.string.InterstitialAd_unit_id));
}
public void openAd() {
runOnUiThread(new Runnable() {
public void run() {
// Create ad request
AdRequest adRequest = new AdRequest();
// Begin loading your interstitial
interstitial.loadAd(adRequest);
// Set Ad Listener to use the callbacks below
interstitial.setAdListener(new AdListener() {
@Override
public void onReceiveAd(Ad arg0) {
if (interstitial.isReady()) {
interstitial.show();
}
}
@Override
public void onPresentScreen(Ad arg0) {
}
@Override
public void onLeaveApplication(Ad arg0) {
}
@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
}
@Override
public void onDismissScreen(Ad arg0) {
}
});
}
});
}
我在游戏结束时调用 openAd() 方法
public synchronized void GameOver() {
if (adounter >= this.getResources().getInteger(R.integer.add_shows_every_X_gameovers)) {
openAd();
adounter = 0;
}
adounter++;
}
非常感谢你,对不起我的英语不好。