Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admob SMART_BANNER size

Tags:

android

admob

The AdSize class has getWidthInPixels() and getHeightInPixels() methods to obtain size of the ad. Although, they work correctly for BANNER, they don't work SMART_BANNER. They always return -2.

Can you please suggest me a way to fetch AdView size during run-time?

like image 780
Ally Avatar asked Jan 04 '13 18:01

Ally


People also ask

What is size of AdMob banner?

Banner ad guidance: 300x250 - Google AdMob Help.

What is smart banner AdMob?

Smart Banners are ad units that render screen-width banner ads on any screen size across different devices in either orientation. Smart Banners detect the width of the device in its current orientation and create the ad view that size. Three ad heights are implemented in smart banners: Ad height.

What size is an app banner?

Mobile banner ads Mobile banner ad sizes may vary, but the most standard banner sizes are 320×480, 300×250 and 320×50 for smartphones and 728×90, 768×1024 and 300×600 mobile ad units for tablets. One of the most popular banner sizes is 320×50 mobile ad. Its success is due to its low price for advertisers.


1 Answers

If you're using the Google Play services library, you can simply use:

int widthPixels = AdSize.SMART_BANNER.getWidthInPixels(this);
int heightPixels = AdSize.SMART_BANNER.getHeightInPixels(this);

In the old standalone Android AdMob SDK, you have to do it the hacky way:

Disclaimer: This is the incorrect way to create an AdSize. Do NOT pass this AdSize into the AdView constructor!

Hopefully the smart banner implementation will be fixed in future versions so you don't have to do this hacky workaround. But here is how it can be done:

// This testSize should not be passed to the AdView constructor.
// Always pass AdSize.SMART_BANNER instead.
AdSize testSize = AdSize.createAdSize(AdSize.SMART_BANNER, this);
int widthPixels = testSize.getWidthInPixels(this);
int heightPixels = testSize.getHeightInPixels(this);
// testSize should not be referenced past this point.
like image 139
Eric Leichtenschlag Avatar answered Nov 06 '22 03:11

Eric Leichtenschlag