Hi I’m starting out integrating admobs and can’t seem to get an adlistener event.
I’ve got this code:
main.lua:
appID = “ca-app-pub-8278249997676996/7462506469”
ads = require(“ads”)
– Create a text object to display ad status
statusText = display.newText( “ad status text”, 0, 0, native.systemFontBold, 22 )
statusText:setTextColor( 255 )
statusText:setReferencePoint( display.CenterReferencePoint )
statusText.x, statusText.y = display.contentWidth * 0.5, 160
– Set up ad listener.
function adListener( event )
statusText.text = “got an ad listener event!”
– event table includes:
– event.provider
– event.isError (e.g. true/false )
local msg = event.response
– just a quick debug message to check what response we got from the library
print("Message received from the ads library: ", msg)
if event.isError then
statusText:setTextColor( 255, 0, 0 )
statusText.text = "Error Loading Ad " … msg
statusText.x = display.contentWidth * 0.5
--showAd( “banner” )
else
statusText:setTextColor( 0, 255, 0 )
statusText.text = "Successfully Loaded Ad : " … msg
statusText.x = display.contentWidth * 0.5
end
end
– Initialize the ‘ads’ library with the provider you wish to use.
if appID then
print(“initialising admob”)
ads.init( “admob”, appID, adListener )
end
and
anotherfile.lua
statusText.text = “Let’s show an ad please”
ads.show( “banner”, {x=0, y=0} )
The statusText.text changes to "let’s show an ad pleas"e, and ads.show( is the next line of code. But there is no further change to statusText.text, which means the adListener is not being called. There’s also no ad being shown.
In my build settings I have:
androidPermissions =
{
“android.permission.READ_PHONE_STATE”,
“android.permission.ACCESS_NETWORK_STATE”,
“android.permission.VIBRATE”,
“android.permission.INTERNET”
},
plugins =
{
– key is the name passed to Lua’s ‘require()’
[“CoronaProvider.ads.admob”] =
{
– required
publisherId = “com.sportspunter”,
},
},
Any suggestions welcome please!
thanks