admob positioning problem

Hi @tarun9, I’ve updated my library, here is the code:

if( not \_G.fx.ads ) then \_G.fx.ads = {height = 0, rateShown = false} end local fxAds = \_G.fx.ads

_G.w = display.contentWidth

_G.h = display.contentHeight

local ads = require(“ads”) local function fxAdListener(event) table.dump(event) end function fxAds.init() print(‘initializing ads’) – Load Corona ‘ads’ library local baseCalculation = w / 320 if system.orientation ~= “portrait” then baseCalculation = h / 320 end if fx.device.isApple then if fx.device.isTablet then fxAds.bannerWidth = w if system.orientation ~= “portrait” then fxAds.bannerHeight = baseCalculation * 30 else fxAds.bannerHeight = baseCalculation * 32 end else fxAds.bannerWidth = w if w > h then fxAds.bannerHeight = baseCalculation * 32 else fxAds.bannerHeight = baseCalculation * 50 end end – The name of the ad provider. local adNetwork = “iads” local appID = appInfo.ads.iAds ads.init(adNetwork, appID, fxAdListener) elseif fx.device.isAndroid then if fx.device.isTablet then fxAds.bannerWidth = w fxAds.bannerHeight = baseCalculation * 90 else fxAds.bannerWidth = w fxAds.bannerHeight = baseCalculation * 50 end --fxAds.bannerHeight = fxAds.bannerHeight / 2 – The name of the ad provider. local adNetwork = “admob” local appID = appInfo.ads.adMob ads.init(adNetwork, appID, fxAdListener) end end function fxAds.showBanner(x, y, params) if fx.device.isSimulator then if params.srpH == “bottom” then y = y - fxAds.bannerHeight end fxAds.adBox = display.newGroup() local o = display.newRect(fxAds.adBox, x+fxAds.bannerWidth/2, y+fxAds.bannerHeight/2, fxAds.bannerWidth, fxAds.bannerHeight) o:setFillColor(255, 0, 0) --o = fx.ui.newText(fxAds.adBox, “Ads Here”, 0, 0, native.systemFont, iif(fx.device.isTablet, 30, 25)) --o.x = x + fxAds.bannerWidth/2 --o.y = y + fxAds.bannerHeight/2 elseif fx.device.isApple then ads.show(“banner”, {x=x, y=y, testMode=appInfo.mode == “TESTING”}) elseif fx.device.isAndroid then ads.show(“banner”, {x=x, y=y, testMode=appInfo.mode == “TESTING”}) end end function fxAds.hide() ads.hide() end fxAds.init() — Example to show the ads on the Top fx.ads.showBanner(0, 0, {}) — Example to show the ads on the bottom fx.ads.showBanner(0, display.contentHeight, {srpH = “bottom”})

At last there are 2 example of how to place the ads on the top and the bottom of the screen. I’ve also created a github repository for my framework. You can download the code at: https://github.com/juancsdc/fx.sdk

The framework is still under development, but at least you can use the ads module.

Hope this can help you.

Does this work for landscape orientation?

If not, any idea what should it look like for landscape?

Regards,

Damir.

The example I gave before, or the code on github works both in portrait and landscape. I could not test it in many devices, if it is not working for some device please let me know and I’ll fix it.

I need ads at the bottom (Android).

I see you use this for Android:

y = display.contentHeight

That does not work for me.

Thanks for your quick reply.

In short this is what you are using for android (portrait mode):

if tablet then adY = display.contentHeight - (display.contentWidth / 320 \* 90) else adY = display.contentHeight - (display.contentWidth / 320 \* 50) end  

Right?

But this did not work well. I have tried this on Nexus 7 (2013), LG optimus G pro and in both case the ad was way up from the bottom.

Then I modified and used this code:

if table then              adY = display.contentHeight - display.screenOriginY - (display.contentWidth / 320 \* 90) else         adY = display.contentHeight - display.screenOriginY - (display.contentWidth / 320 \* 50) end  

The above code worked well for the devices I mentioned. 

What’s your view on the above code???

I tested with Galaxy Tab & Sony Xperia, and I think tarun9 is right, his modified code works

adY = display.contentHeight - display.screenOriginY - (display.contentWidth / 320 \* 50)

However I am still seeing two problems:

(1) In Sony Xperia, the ad is placed at the exact bottom, which is perfect. However in Galaxy Tab, there is still 3 pixels space under the ad where I can see my background underneath. My config.lua is 320x480, letterbox. Where does this 3-pixels space come from? How to avoid it?

(2) How to determine if Android device is a tablet or not? Should I use this (from this article:  http://www.coronalabs.com/blog/2013/04/30/new-system-info-properties/)

if ( system.getInfo( "androidDisplayWidthInInches" ) \> 5 or system.getInfo( "androidDisplayHeightInInches" ) \> 5 ) then print( "Is tablet" ) end

However, if I use this to decide, my Galaxy Tab 3 is categorized as a tablet (the height is over 6 inches). And if it’s a tablet, the ad height should be 90. But it’s wrong. It’s still 50.

Anyone tested with a real Android tablet? The ad height is 90 or always 50?

The question is where from did the 90 and 50 come from?

Smart-banners for Android in landscape are 32px.

@ubj3d.android

Please take a look at this Android smart banner size: https://developers.google.com/mobile-ads-sdk/docs/admob/smart-banners

I think 90 comes from 800x90 (Android tablets in Portrait)

and 50 comes from 320x50 (iPhone, Windows Phone 8, and most Android phones in Portrait)

hmm… so why is there “(display.contentWidth / 320 * 90)” ???

Thanks Joe, that is correct, the banner size are the one published by Admob.

The calculation of (display.contentWidth / 320 * 90) is because corona when building the banner considers a contentWidth of 320, if your config.lua defines your screen size as that then the admob banner is just 90, but if you use any other configuration, like i’m using, (as described in the ultimate config lua) then you need to escalate the banner properly.

local widthInInches = display.pixelWidth / approximateDpi local heightInInches = display.pixelHeight / approximateDpi if widthInInches \>=5 or heightInInches \>= 5 then -- its a tablet    adX = display.screenOriginX    adY = display.contentHeight - display.screenOriginY - (display.contentWidth / 320 \* 90) else    adX = display.screenOriginX    adY = display.contentHeight - display.screenOriginY - (display.contentWidth / 320 \* 50) end  

This is the calculation for finding out if the device is a tablet or phone.

First, a word of warning.  Properties “androidDisplayWidthInInches” and “androidDisplayHeightInInches” have been known to return the wrong values on some devices.

http://forums.coronalabs.com/topic/39312-tablet-detection/?p=203948

@juan.csdc

Shouldn’t it be “(display.contentWidth / 800 * 90)”  instead of 320?

And how do you determine if Android device is a tablet or not? 

My Galaxy Tab 3 seems using 320x50 banner while it might be considered as a tablet too.

Check my reply above.

Hi guys, here is my code to identify devices and properties

fx.device = { isSimulator = system.getInfo("environment") == "simulator", model = system.getInfo("model"), width = math.floor((displayWidth/display.contentScaleX) + 0.5), height = math.floor((displayHeight/display.contentScaleY) + 0.5), isApple = false, isAndroid = false, isGoogle = false, isNook = false, isKindleFire = false, isTablet = false, platformName = system.getInfo("platformName"), platformVersion = system.getInfo("platformVersion"), } if string.sub(fx.device.model, 1, 2) == "iP" then fx.device.isApple = true -- Are we on a tablet? if string.sub(fx.device.model, 1, 4) == "iPad" then fx.device.isTablet = true end elseif fx.device.platformName == "Android" or fx.device.isSimulator then -- Simulator? There's no way to know if the sim. is android, so let's assume that fx.device.isAndroid = true -- If it is android let's assume it is google fx.device.isGoogle = true -- All of the Kindles start with "K", although Corona builds before #976 returned -- "WFJWI" instead of "KFJWI" (this is now fixed, and our clause handles it regardless) if model == "Kindle Fire" or model == "WFJWI" or string.sub(fx.device.model, 1, 2) == "KF" then fx.device.isKindleFire = true fx.device.isGoogle = false --revert Google Play to false end -- Are we on a Nook? if string.sub(fx.device.model, 1 ,4) == "Nook" or string.sub(fx.device.model, 1, 4) == "BNRV" then fx.device.isNook = true fx.device.isGoogle = false --revert Google Play to false end -- Are we on a tablet? if system.getInfo("androidDisplayWidthInInches") then if(system.getInfo("androidDisplayWidthInInches") \> 5 or system.getInfo("androidDisplayHeightInInches" ) \> 5) then fx.device.isTablet = true end end else print("Unknown device") end if (display.pixelHeight/display.pixelWidth) \> 1.5 then fx.device.isTall = true end

As tarun9 said, I used the 5 inches as a trigger

@juan.csdc

You should use the below code to get the width/height in inches.

local widthInInches = display.pixelWidth / approximateDpi
local heightInInches = display.pixelHeight / approximateDpi
if widthInInches >=5 or heightInInches >= 5 then
– its a tablet

end

Even I use the following code to see if a device is a tablet

local widthInInches = display.pixelWidth / approximateDpi local heightInInches = display.pixelHeight / approximateDpi if widthInInches \>=5 or heightInInches \>= 5 then -- its a tablet end

My Galaxy Tab returns

widthInInches  =     3.7558685446009    

heightInInches =     6.0093896713615

So it is categorized as a tablet. 

However, the height of the admob Ad shown in the device is actually 50, not 90.

It seems there is no correct way to determine if a device is a tablet that uses taller admob ads?

This is just plain crazy.

I struggle with this for a few days and there is no solution.

HOW TO POSITION THE ADMOB BANNER AT THE BOTTOM IN LANDSCAPE?

Here is my config.lua:

local aspectRatio = display.pixelHeight / display.pixelWidth -- background size: width = 640\*1.125=720, height = 960\*1,1875=1140 application = { content = { width = aspectRatio \> 1.5 and 640 or math.ceil( 960 / aspectRatio ), height = aspectRatio \< 1.5 and 960 or math.ceil( 640 \* aspectRatio ), scale = "letterBox", fps = 60, }, }

I guess the formula should be like this:

adY = display.contentHeight - display.screenOriginY - bannerHeight

For all devices I tested I got display.screenOriginY=0 so the formula is simple:

adY = display.contentHeight  - bannerHeight

The milion dollar question is how to determine the bannerHeight ???

I have tested on 4 devices and found that the banner height is different on all of them.

Here is the complete table:

bannerHeight.jpg

I have tried many, many variations to get the formula which would give me the bannerHeight from contentWidth,contentHeight,pixelWidth,pixelHeight,ascpectRatio but with no success.

Is there really noone using admob at bottom in landscape?

HELP PLEASE!

I would vote for Corona to include an API call to get the banner height, if not this is impossible. Also for iAds, even if you set y=display.contentHeight, and the banner is beautifully shown at the bottom of the screen, to render everything else I need to know the ad height.

+1 for this API

Guys, I just created a feature request for this, please support it so that Corona would implement it!

Here is the link to the idea:

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/5245292-implement-banner-height-as-api-call-for-the-ads-mo

I gave it myself 3 votes

I thought you find a solution (although it isn’t working for me) ?

This is getting even more weird.

I continued to test admob, now in portrait on the same devices and config.lua as above.

Here are the results of the banner heights:

Xperia = 100

LG = 100

Transformer = 72

Galaxy Tab = 96