我在使用 AdMob 插页式广告的游戏中遇到了一个大问题。广告在计时器结束或玩家退出回合时显示。所以在活动结束时。没有连接的时候就好了。活动的变化很快。当有神和快速连接一样。问题是当有一个有价值的连接并且当玩家完成回合时,有很长一段时间(有时广告从未显示)活动不会改变,所以玩家可以继续玩,即使时间很艰难超过。这是我的代码:
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
Intent data = new Intent();
data.putExtra("team", team);
myDB.close();
data.putExtra("A", A);
data.putExtra("B", B);
// data.putExtra("contaDb", this.contDb);
setResult(1, data);
finish();
}
public void onLeaveApplication1(Ad arg0) {
// TODO Auto-generated method stub
}
public void onPresentScreen1(Ad arg0) {
// TODO Auto-generated method stub
}
public void onReceiveAd(Ad ad) {
Log.d("OK", "Received ad");
if (ad == interstitial) {
if(ad.isReady())
interstitial.show();
}
Intent data = new Intent();
data.putExtra("team", team);
myDB.close();
data.putExtra("A", A);
data.putExtra("B", B);
// data.putExtra("contaDb", this.contDb);
setResult(1, data);
finish();
}
public void onDismissScreen1(Ad arg0) {
// TODO Auto-generated method stub
}
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
和:
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) this
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null)
return false;
return ni.isConnected();
}
public void visualizzaRisultatoActivity() {
if (isOnline()) {
interstitial = new InterstitialAd(this, "0976ebb3525a494a");
// Create ad request
AdRequest adRequest = new AdRequest();
// Begin loading your interstitial
interstitial.loadAd(adRequest);
// Set Ad Listener to use the callbacks below
interstitial.setAdListener(this);
} else {
Intent data = new Intent();
data.putExtra("team", team);
myDB.close();
data.putExtra("A", A);
data.putExtra("B", B);
// data.putExtra("contaDb", this.contDb);
setResult(1, data);
finish();
}
}
VisualizzaRisultatoActivity 在时间结束或玩家取消回合时被调用。提前致谢