使用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。提前致谢
最佳答案
最佳做法是在游戏过程中预加载您的插页式广告,然后在游戏结束时对其进行轮询:
if(interstitial.isReady()) {
interstitial.show();
}
插页广告调用
isReady
时,会设置onReceiveAd
标志,但您可以等到游戏结束时再显示它。请注意,您可能应该在游戏活动中而不是在VisualizzaRisultatoActivity中请求/显示插页式广告。插页式广告应与您传递给其构造函数的活动相同。