How to create Banners with Admob?

1

My problem is that they do not appear or show the banner on the screen, now my code that is from the official website of admob does not work, the page is: this .

The code is this:

    private void crear(){
    SurfaceView gameView = new SurfaceView(this);

    // Create and load the AdView.
    adView = new AdView(this);
    adView.setAdUnitId("ca-app-pub-1765002374395487/9026293652");
    adView.setAdSize(AdSize.SMART_BANNER);

    // Create a RelativeLayout as the main layout and add the gameView.
    RelativeLayout mainLayout = new RelativeLayout(this);
    mainLayout.addView(gameView);

    // Add adView to the bottom of the screen.
    RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    mainLayout.addView(adView, adParams);

    showBanner();
}

private void showBanner() {
      adView.setVisibility(View.VISIBLE);
      adView.loadAd(new AdRequest.Builder()
          .addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build());
    }

This code is the same as that given by admob except that I have modified it by placing it within a method.

If you know where I fail please tell me or know another way, I'll be happy to hear your idea. Thanks

    
asked by Abraham.P 17.03.2017 в 18:20
source

1 answer

3

You must contain the permissions within the AndroidManifest.xml, remember that your internet connection application must allow:

<uses-permission android:name="android.permission.INTERNET" />

It is important to check that the AdUnit id corresponds to an active ad, if the above is correct, I can tell you that your implementation is correct but apparently the problem is with SMART_BANNER that does not have space required to deploy,

  

SMART_BANNER

     
  • vertical orientation requires 411x50 dp
  •   
  • horizontal orientation requires 683x50 dp
  •   

Try showing another measure as LARGE_BANNER :

It is important to review the LogCat where it will show what is necessary for the deployment. It is not necessary to "link the application that is in google play, with admob", precisely in the LogCat you can suggest you add a test device to be able to display the ads:

  

Ads: Use   AdRequest.Builder.addTestDevice ("ABCDEF012345") to   get test ads on this device.

example:

  AdRequest adRequest = new AdRequest.Builder().addTestDevice("ABCDEF012345")
                    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .build();

Common messages that tell us that the ad can not be loaded because it has inadequate space.

  
  • W / Ads: Not enough space to show ad. Needs 411x50 dp, but only has   379x571 dp.
  •   
  • W / Ads: Not enough space to show ad. Needs 683x50 dp, but   only has 651x307 dp.
  •   
    
answered by 17.03.2017 в 19:09