Admob Height always 0 (Android)

Hi 

I kept getting admob height as 0 on my Android build.  Any idea what is happening?

local function adListener(event)

    if ( event.isError ) then

        print(“error”

    else

        native.showAlert( “Title”, "Ad Height is " … ads.height(), { “OK”})

    end

end

I am also using adaptive layout.

Are you actually showing an ad on the screen at the time this check is done?

It been a while since I checked this, but I believe I had to actually show at least 1 admob banner ad before I got the correct height.

Yes, the admob banner did show up but the value is 0.

Can you post some code?

iOS or Android?

Same thing is happening to me on android.

ads.init( adProvider, appID, adListener ) ads.show( "banner", { x=display.screenOriginX, y=10000000} ) print( ads.height() )

The ad shows fine. But always prints 0 for the ad height.

I believe both ads.init() and ads.show() are non-blocking functions. By that I mean they return almost immediately and don’t wait until all their work is done before returning.

Try putting in a delay and checking the ads.height again after a few seconds.

Good catch @elbowroomapps.  Several people have reported this, and this very well could be the reason.  I would take it one step further and suggest that instead of a timer with a brief delay, that they put this in their listener function for when they get a successful ad show and adjust the interface then since thats when you know if you got an ad or not.

Rob

Thanks, throwing it in the listener on a successful ad show did the trick!

Are you actually showing an ad on the screen at the time this check is done?

It been a while since I checked this, but I believe I had to actually show at least 1 admob banner ad before I got the correct height.

Yes, the admob banner did show up but the value is 0.

Can you post some code?

iOS or Android?

Same thing is happening to me on android.

ads.init( adProvider, appID, adListener ) ads.show( "banner", { x=display.screenOriginX, y=10000000} ) print( ads.height() )

The ad shows fine. But always prints 0 for the ad height.

I believe both ads.init() and ads.show() are non-blocking functions. By that I mean they return almost immediately and don’t wait until all their work is done before returning.

Try putting in a delay and checking the ads.height again after a few seconds.

Good catch @elbowroomapps.  Several people have reported this, and this very well could be the reason.  I would take it one step further and suggest that instead of a timer with a brief delay, that they put this in their listener function for when they get a successful ad show and adjust the interface then since thats when you know if you got an ad or not.

Rob

Thanks, throwing it in the listener on a successful ad show did the trick!

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.