Hello, can anyone help me with this problem? When I run my app in the emulator, the ad usually appears every time, but when I run on my phone the ad only appeared once and did not appear again. What can this be? I'm using the Gdx library for my game
Class Android Launcher
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);
}
}
I'm initializing the ad in the create method of my game ..
public void create () {
.....
.....
handler.showAds(toggle); //toggle é sempre true..
}