1

I'm trying to integrate ads into my Android app using AdWhirl and AdMob.

The AdWhirl site gave me the following code to use:

AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.layoutAdWhirl);

int diWidth = 320;
int diHeight = 52;
int density = (int) getResources().getDisplayMetrics().density;

int scaledWidth = (int) (diWidth * density);
int scaledHeight = (int) (diHeight * density);

adWhirlLayout.setAdWhirlInterface(this);
adWhirlLayout.setMaxWidth(scaledWidth);
adWhirlLayout.setMaxHeight(scaledHeight);

This works just fine on some of my emulators, but when I try some smaller or older emulators, I get the following error in LogCat:

Not enough space to show ad! Wants: 480, 75, Has: 320, 52

What am I supposed to do if I'm using their code for requesting an appropriately sized ad, but then they won't display that ad?

Eric Leichtenschlag
  • 8,881
  • 1
  • 28
  • 28
Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229

1 Answers1

5

Couple of things here:

  1. The AdMob ad needs 320x50 density-independent pixels to show an ad. Every Android device, even the old small ones, meet these specs. The small 240x400 pixel phones are low density, meaning 1px = 0.75dp, and so there are still 320dp in portrait mode to show an ad. Your small emulators are probably in such a state where they are really small (low pixel count), but have medium or high density such that the emulator isn't 320dp wide. Check your emulator settings - they are likely not representative of any device.

  2. The above code to calculate max width and max height isn't necessary. As long as the xml gives the AdWhirlView 320x52dp size (or more preferred, wrap_content), you don't need to grab the device density to calculate these values manually.

UPDATE:

I have a new theory. The error you're displaying where the AdMob SDK Wants: 480, 75 means you're running on a high-density device, because it multiplied 320x50dip by 1.5. However, the piece of code:

int density = (int) getResources().getDisplayMetrics().density;

is casting 1.5 to 1, so the max width and height of the adWhirlLayout were incorrectly set to 320x52 pixels. This would probably have been an issue for low density devices as well, because 0.75 density would have been casted to 0. It may have worked on medium density devices.

The AdWhirl documentation is a bit outdated, but it probably should have said float density instead of int density.

Eric Leichtenschlag
  • 8,881
  • 1
  • 28
  • 28
  • The scale density is 1 (an mdpi device, very common), so scaledWidth and scaledHeight were 320 x 50. The device was 480 pixels wide though and the xml was "fill_parent". Commenting out the setMaxWidth() and setMaxHeight() calls made the error go away... I still think their API is whack... not exactly my solution, but I think your option #2 should work to fix it, so I'll accept this answer. – Kenny Wyland Mar 12 '12 at 01:38
  • I think I figured it out. You were probably running on a WVGA800 emulator, which is 1.5 density, but the code above casted it to a 1, causing the view to be too small. I've updated my answer. – Eric Leichtenschlag Mar 12 '12 at 22:47
  • @Eric: what you're saying is correct. Just let me add the very strong problem is that when raises the warn "Not enough space to show ad!" the request is considered onReceiveAd successful even not displayed and this is breaking the backfill chain provided by the mediation layer (in this case AdWhirl) – Lisitso May 11 '13 at 16:26
  • Yes, this check is not made until after onReceiveAd() is called, so AdWhirl won't try the next network. However, if you're having this problem, that means your AdWhirlView is too small anyways, and a 320x50dp ad from any ad network is going to be too big to fit into that space. – Eric Leichtenschlag May 13 '13 at 21:34