1

我在使用 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 在时间结束或玩家取消回合时被调用。提前致谢

4

1 回答 1

1

最佳做法是在游戏期间预加载您的插页式广告,然后在游戏结束时轮询它是否准备就绪:

if(interstitial.isReady()) {
  interstitial.show();
}

isReady当您的插页式广告调用时会设置该标志onReceiveAd,但您可以等到游戏结束时再显示它。请注意,您可能应该在游戏活动中请求/显示您的插页式广告,而不是您的 VisualizzaRisultatoActivity。插页式广告应与您传递给其构造函数的相同活动一起显示。

于 2013-04-27T02:05:21.007 回答