Warning: sorry for my English. Didnt find admob forum in plugins section, so ask here.
Here the problem - I successfully integrate admob into my app, but i cant position it well for different android devices.
My config.lua
application = { content = { width = 780, height = 1024, scale = "zoomEven", fps = 60, }, }
Yes, I use zoomEven , cause dont like any croping.
Here my build.setting
-- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight settings = { orientation = { default = "portrait", supported = { "portrait", } }, iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend --[[-- iOS app URL schemes: CFBundleURLTypes = { { CFBundleURLSchemes = { "fbXXXXXXXXXXXXXX", -- example scheme for facebook "coronasdkapp", -- example second scheme } } } --]] } }, -- Android permissions androidPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", "android.permission.READ\_PHONE\_STATE", }, plugins = { -- key is the name passed to Lua's 'require()' ["CoronaProvider.ads.admob"] = { -- required publisherId = "com.coronalabs", }, }, }
For this app I want banner ad in the bottom of the screen. I read somewhere, that corona supports only smart banners for admob.
From here https://developers.google.com/mobile-ads-sdk/docs/admob/smart-banners I learn that there are only 50 and 90 pixel heights for portait orientered apps for any android device. 90 for tablets and 50 for others.
So, for correct positioning, I need to know if the device is a tablet or phone, then convert my config pixels into real ones.
ads.show( "banner", { x = display.screenOriginX , y = display.screenOriginY + display.viewableContentHeight - adsDy } )
Where adsDy - height of banner in real size. To get it i use next code:
local adsDy = 0 if system.getInfo( "androidDisplayWidthInInches" ) then if( system.getInfo( "androidDisplayWidthInInches" ) \> 5 or system.getInfo( "androidDisplayHeightInInches" ) \> 5 ) then --is a tablet adsDy = 90 else adsDy = 50 end adsDy = adsDy \* ( display.viewableContentHeight / (system.getInfo("androidDisplayYDpi") \* system.getInfo( "androidDisplayHeightInInches" )) ) end
(system.getInfo(“androidDisplayYDpi”) * system.getInfo( “androidDisplayHeightInInches” )) - this must return the real pixel height of device. But for my asus tpad 300 it returns 1232 instead of 1280. Or it doesnt count the navigation bar and it’s 48 pix in height?
Anyway, with this way I can get good Y positioning on Asus TPad 300 and it begins from left side of screen, but it’s a little wider than the screen. But Galaxy SIV shows it very bad:
It seems about 33% of real height of banner and 80% of its width.
I try to solve this case 2 days but have no idea yet. Searching on corona forums doesnt give a result also.
I would be glad to hear any ideas and solutions!