-1

Hello I am trying to integrated Banner Ad using RevMob in Libgdx. But it is not displaying for some reason.

I am using the following code.

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.activity_game_new);

    AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
    // cfg.useGL20 = false;

    final RelativeLayout gameLayout = new RelativeLayout(this);

    RevMobIntegration revmob = new RevMobIntegration(this);

    RelativeLayout bannerLayout = new RelativeLayout(this);


    RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    adParams.addRule(RelativeLayout.CENTER_VERTICAL);

    bannerLayout.setLayoutParams(adParams);

    game = new MyGdxGame(GameActivity.this, revmob);
    game.setRedirectionListener(this);


    View gameView = initializeForView(game, cfg);


    requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    // Add the libgdx view
    gameLayout.addView(gameView);
//        gameLayout.addView(bannerLayout);

    Log.d("RevMob", "Checking  BannerAd");
    if (revmob.getBannerAd() != null) {
        Log.d("RevMob", "Displaying Called");
        gameLayout.addView(revmob.getBannerAd());
    }


    // Hook it all up
    setContentView(gameLayout);


    this.onPause();
    this.onResume();
    gameLayout.refreshDrawableState();


    initChartboost();


//        startRevMobSession();

}

Here is the RevMobIntegration class :

  public class RevMobIntegration implements RevmobAdInterface {

   private static final String APPLICATION_ID = "YourAdmobAppIDHere";

    // Set this to false when creating the version for the store.
   private static final boolean DEBUG = true;

    private RevMobAdsListener listener;

  private RevMobFullscreen fullscreenAd;
   private RevMobBanner bannerAd;

   private Activity application;
   private RevMob revmob;

  public RevMobIntegration(Activity _application) {
  this.application = _application;

  startRevMobSession();
  }


  public void startRevMobSession() {
  //RevMob's Start Session method:
  revmob = RevMob.startWithListener(application, new RevMobAdsListener() {
     @Override
     public void onRevMobSessionStarted() {
        loadBanner(); // Cache the banner once the session is started
        Log.i("RevMob", "Session Started");
     }

     @Override
     public void onRevMobSessionNotStarted(String message) {
        //If the session Fails to start, no ads can be displayed.
        Log.i("RevMob", "Session Failed to Start");
     }
  }, application.getString(R.string.rev_mob_app_id));
   }


  //RevMob
   public void loadBanner() {
  bannerAd = revmob.preLoadBanner(application, new RevMobAdsListener() {
     @Override
     public void onRevMobAdReceived() {
        showBannerAd(true);
        Log.i("RevMob", "Banner Ready to be Displayed"); //At this point, 
      the banner is ready to be displayed.
     }

     @Override
     public void onRevMobAdNotReceived(String message) {
        Log.i("RevMob", "Banner Not Failed to Load");
     }

     @Override
     public void onRevMobAdDisplayed() {
        Log.i("RevMob", "Banner Displayed");
     }
  });
  }

   @Override
  public void showBannerAd(boolean show) {
  if(show) {
     Log.i("RevMob", "Showing");
     if(bannerAd == null) {
        startRevMobSession();
     } else {
        Log.i("RevMob", "Banner Displayed");
        bannerAd.show();
       }
     } else {
     bannerAd.hide();
  }
  }

  public RevMobBanner getBannerAd() { return bannerAd; }


 }

I have integrated the RevMob in my Activities and it is working fine. But for the Game Screen the ad is initializing but not displaying. Any suggestions?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Nir Patel
  • 357
  • 4
  • 17

1 Answers1

0

It seems revmob.getBannerAd() return null because bannerAd object created when loadBanner(); called. RevMob take some time to start it's session.

if (revmob.getBannerAd() != null) {
     Log.d("RevMob", "Displaying Called");
     gameLayout.addView(revmob.getBannerAd());
}

You can check this repo for clarification also you can take a look of this class.

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65
  • Thanks you were correct. It was not being called. So I put a delay of 5 seconds and it is called, check it with the LOG "Displaying Called". But there is not ad still appearing on the screen yet. Anything else I should try? – Nir Patel Apr 24 '17 at 10:20
  • why don't you try my repo ? – Abhishek Aryan Apr 24 '17 at 10:31
  • Yes trying that. In RevMobHelper you have commented following code //if(banner!=null) { //layout.addView(banner, topParams); //banner.setBackgroundColor(Color.BLACK); //} I need to uncomment that right? – Nir Patel Apr 24 '17 at 11:20
  • use `addToLayout` method of RevmobHelper instead of `embedView`, `addToLayout` method called just after session start. Don't uncomment those commented lines – Abhishek Aryan Apr 24 '17 at 11:27
  • 1
    Thanks a ton. Had to put delay here as well. But still, got it up and running. Thanks again. – Nir Patel Apr 24 '17 at 13:18