Admob Height always 0 (Android)

Using this code:

local ads = require( "ads" ) local appId = "ca-app-pub-0123456789012345/0123456789" local function adMobListener( event ) local height = ads.height() print("Local height: ",tostring( height)) print( "Height in listener: "..ads.height()) end ads.init( "admob", appId, adMobListener ) ads:setCurrentProvider( "admob" ) ads.show( "banner", { x=0, y=0 } )

This printed in my console.log:

I/Ads     (29368): Ad finished loading.
I/Corona  (29368): Local height:     47.6
I/Corona  (29368): Height in listener: 47.6

If you are not getting height values, we probably need to see your build.settings and config.lua. This appears to be working as expected.

Rob

Dear Rob! 

I used your code and have the following in console: 

12-01 14:56:15.771 16568-16595/? I/Corona: Local height: 012-01 14:56:15.772 16568-16595/? I/Corona: Height in listener: 0

my build.settings:

settings = { orientation = { default = "portrait", supported = { "portrait", } }, androidPermissions = {   "android.permission.INTERNET",   "android.permission.ACCESS\_NETWORK\_STATE",   }, plugins =     {     ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs"         },     }, }

 I don’t use config.lua. 

Version 2015.2731 (2015.10.5)

Any ideas?

I found the reason why ads.height() returns 0 in my case. I don’t have  scale in config.lua!

When I add for example  scale =  letterbox  it works fine. But in my games I like to use a whole screen space that’s why I don’t use any scaling. There is no information in  ads.height() documentation that it works correctly only if scale used.  Do you plan to fix  this function to make it working in case of missing scale?

You should specify a scale. You should also set your width and height in there too.

Hello!

my simple code always return 0 when I call ads.height() on Android.

main.lua:

local ads = require( "ads" ) local function adMobListener( event ) print( "Height in listener: "..ads.height()) end     ads.init( "admob", "ca-app-pub-XXXXX", adMobListener ) ads:setCurrentProvider( "admob" ) ads.show( "banner", { x=0, y=0 } ) local height = ads.height() print("Local height: ",tostring( height))

build.settings

settings = { orientation = { default = "portrait", supported = { "portrait", } }, androidPermissions = {   "android.permission.INTERNET",   "android.permission.ACCESS\_NETWORK\_STATE",   }, plugins =     {     ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs"         },     }, }

I tested it on 2 devices (Samsung Galaxy S3 and Sony Xperia Z3 tablet)

and prints in android monitor are always the same:

09-30 01:53:32.421  32680-32705/? I/Corona﹕ Local height: 0 09-30 01:53:34.491  32680-32705/? I/Corona﹕ Height in listener: 0

Corona builds: 2015.2722  and 2015.2646

What do I do wrong?  Could you give me a small example where ads.height() return something different from 0  on Android?

local ads = require( "ads" ) local function adMobListener( event ) local height = ads.height() print("Local height: ",tostring( height)) print( "Height in listener: "..ads.height()) end ads.init( "admob", "ca-app-pub-XXXXX", adMobListener ) ads:setCurrentProvider( "admob" ) ads.show( "banner", { x=0, y=0 } )  

You need to get the ads.height after showing the ad. So, your code should be :

You mean I should call ads.height() in adMobListener?  That’s what exactly I did. 

If you take a look at my code you can see two calls of height() method: first is right after ads.show() call, second is in adMobListener inside print:   print( "Height in listener: "…ads.height())

Both returns 0.

Can you file a bug report please? You need a simple demo that shows the problem. Include your main.lua, config.lua, build.settings and any other files need to build and run the app. Compress a folder with all those files and make a .zip file. Use the “Report a bug” link at the top of the page. When you get the confirmation email, please post the bug’s CaseID back here.

Thanks

Rob

I am using build 2015.2728 and it works fine with on my Android device.

Using this code:

local ads = require( "ads" ) local appId = "ca-app-pub-0123456789012345/0123456789" local function adMobListener( event ) local height = ads.height() print("Local height: ",tostring( height)) print( "Height in listener: "..ads.height()) end ads.init( "admob", appId, adMobListener ) ads:setCurrentProvider( "admob" ) ads.show( "banner", { x=0, y=0 } )

This printed in my console.log:

I/Ads     (29368): Ad finished loading.
I/Corona  (29368): Local height:     47.6
I/Corona  (29368): Height in listener: 47.6

If you are not getting height values, we probably need to see your build.settings and config.lua. This appears to be working as expected.

Rob

Dear Rob! 

I used your code and have the following in console: 

12-01 14:56:15.771 16568-16595/? I/Corona: Local height: 012-01 14:56:15.772 16568-16595/? I/Corona: Height in listener: 0

my build.settings:

settings = { orientation = { default = "portrait", supported = { "portrait", } }, androidPermissions = {   "android.permission.INTERNET",   "android.permission.ACCESS\_NETWORK\_STATE",   }, plugins =     {     ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs"         },     }, }

 I don’t use config.lua. 

Version 2015.2731 (2015.10.5)

Any ideas?

I found the reason why ads.height() returns 0 in my case. I don’t have  scale in config.lua!

When I add for example  scale =  letterbox  it works fine. But in my games I like to use a whole screen space that’s why I don’t use any scaling. There is no information in  ads.height() documentation that it works correctly only if scale used.  Do you plan to fix  this function to make it working in case of missing scale?

You should specify a scale. You should also set your width and height in there too.