AdMob 广告仅展示一次



谁能帮我解决这个问题?当我在模拟器中运行我的应用时,广告每次都会出现,但是当我在手机上运行时,广告只出现一次,不会再次出现。我正在为我的游戏使用 Gdx 库

类安卓启动器

public class AndroidLauncher extends AndroidApplication implements AdHandler {
private static final String TAG = "AndroidLauncher";
private final int SHOW_ADS = 1;
private final int HIDE_ADS = 0;
protected AdView adView;
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case SHOW_ADS:
adView.setVisibility(View.VISIBLE);
break;
case HIDE_ADS:
adView.setVisibility(View.GONE);
break;
}
}
};
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
View gameView = initializeForView(new BolsoBird(this), config);
layout.addView(gameView);
adView = new AdView(this);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
int visibility  = adView.getVisibility();
adView.setVisibility(AdView.GONE);
adView.setVisibility(visibility);
Log.i(TAG,"Ad loaded...");
}
});
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("xxxxxxx");
AdRequest.Builder builder = new AdRequest.Builder();
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(adView, adParams);
adView.loadAd(builder.build());
setContentView(layout);
}
@Override
public void showAds(boolean show) {
handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
}
}

我正在游戏的创建方法中初始化广告..

public void create () {
.....
.....
handler.showAds(toggle); //toggle is true every time..
}

谢谢大家。

尝试将AdView放置在版式内,然后改为更改版式公开范围设置可见性的正确方法是使用 View.GONE,但您已在AdListener((中指定了AdView.GONE

相关内容

  • 没有找到相关文章

最新更新