Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining actual height of an Admob SmartBanner in Unity for Android

So I'm implementing admob banners into my Unity 4.6 Android game. I have the banner at the bottom and need to account for it in my UI. Specifically I need to know exactly how tall it is, but I'm having trouble with figuring this out.

Based on the information found here the Smart Banner should be 32, 50, or 90 pixels tall, depending on device height. This doesn't seem to typically be the case though.

Some searching would seem to indicate this is because of density pixels. So I attempt to convert the stated pixel height using px = dp * (Screen.dpi/ 160). So for example if I determine the banner height should be 90 pixels, I would use bannerHeight = 90 * (Screen.dpi / 160). This seems to work on some devices but not others.

For example my Nexus 4 has a DPI of 320. Using the above it would seem to indicate that the banner should be 180 pixels tall, but the banner appears to actually be about 90 pixels tall. But on the Nexus 7 (which has a dpi of 166), the banner appears to be about 120 pixels tall when the formula would indicate it should be ~93.

So I guess I have no idea how to figure out how tall the banner is actually going to be, and I haven't found a way to get this information from the API. My code for calling the banner is pretty stock:

 string adUnitId = "my_id";

 BannerView bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
 AdRequest request = new AdRequest.Builder().Build();
 bannerView.LoadAd(request);
like image 230
Josh DeWolfe Avatar asked Jan 04 '15 03:01

Josh DeWolfe


People also ask

How do I show banner ads in unity?

The first step toward displaying a banner is to create a BannerView object in a C# script attached to a GameObject . For easier ads integration using the Unity Editor, try the new Ad Placements Beta. // Initialize the Google Mobile Ads SDK. // Create a 320x50 banner at the top of the screen.

Can I use Unity ads with AdMob?

You need to add Unity Ads to the mediation configuration for your AdMob ad units. First, sign in to the AdMob UI. If you're deploying your Unity app to both Android and iOS, you need two AdMob ad units, one for each platform.

What is smart banner?

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.


1 Answers

First you need to calculate which Ads google will give you (32 or 50 or 90 ?) for this you can calculate it by screen sizes.

height/dpi = actual height in inches

so, Google says above 720 (with dp of 160dpi) is acctauly 720/160 = 4.5 inch height, above this height, the ads are 90 pixels (dp!) below its 50 dp! 400/160 = 2.5 , below this, ads will be 32 dp

SO! if i have Xiaomi mi3 with 1920x1080 thats, 1920/480dpi = 4 inch height..which will give us 50 dp ads.

with the formula of converting DP to pixel

px = dp * (Screen.dpi/ 160)

50 * (480/160) = 150 pixels height for the ad!

For landscape you need to use as "height" 1080 instead of 1920 1080/480dpi = 2.25 height in landscape this means the ads will be 32 pixels dp

which converts to:

32* (480/160) = 96 pixels in landscape

its too bad google doesn't give enough examples so we can really check ourselves.

Your info page is:

https://developers.google.com/admob/android/banner

like image 165
omri ofir Avatar answered Nov 11 '22 23:11

omri ofir