Also, the test mode I copied from one of your replies isn’t working.
-
Use the build settings file I supplied above, not yours.
-
My code definitely works. I’m using it and two other folks are using it just recently. (Seems admob is suddenly a popular forums question theme) Please check for typos in things like your app id, etc.
For example this does not look right:
"pub-3054113816306190"
Unless you custom specified the ID when you created the admob app, it should look something like this:
"ca-app-pub-2064790293916744/655311234"
PS - In case it is not clear, all the code you posted is not supposed to be in build.settings. You are mixing settings and functional code.
You need these files in your project at a minimum:
- config.lua
- build.settings - Try my exact code above, then add more settings after you get this working.
- main.lua - This is where the calls to require, and showAd(), etc should be (assuming there are no additional files in your app/game).
So this is my updated build.settings:
settings = { plugins = { -- ================================= -- Ads -- ================================= ["plugin.google.play.services"] = { publisherId = "com.coronalabs" }, }, android = { usesPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", }, }, local ads=require("ads") local function adListener( event ) for k,v in pairs( event ) print("adListener ", k, v ) -- so you see everything you get end end ads.init("admob", bannerID, adListener ) ads:setCurrentProvider("admob") ads.load("admob", { appId = bannerID, testMode = true } ) showAd( "top", true ) local unusedWidth = display.actualContentWidth - display.contentWidth local unusedHeight = display.actualContentHeight - display.contentHeight local left = 0 - unusedWidth/2 local top = 0 - unusedHeight/2 local right = display.contentWidth + unusedWidth/2 local bottom = display.contentHeight + unusedHeight/2 }
What’s missing? Also, I couldn’t get it to test mode.
You’re not reading my instructions carefully enough, so I’ll give you explicit code.
Put this in build.settings
settings = { plugins = { ["plugin.google.play.services"] = { publisherId = "com.coronalabs" }, }, android = { usesPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", }, }, }
Make a main.lua file with ONLY this in it (so you can see whether it works):
local unusedWidth = display.actualContentWidth - display.contentWidth local unusedHeight = display.actualContentHeight - display.contentHeight local left = 0 - unusedWidth/2 local top = 0 - unusedHeight/2 local right = display.contentWidth + unusedWidth/2 local bottom = display.contentHeight + unusedHeight/2 local bannerID = "PUT YOUR ID CODE BETWEEN THESE QUOTES" local testMode = true local ads=require("ads") local function adListener( event ) for k,v in pairs( event ) do print("adListener ", k, v ) -- so you see everything you get end end ads.init("admob", bannerID, adListener ) ads:setCurrentProvider("admob") ads.load("admob", { appId = bannerID, testMode = testMode } ) local function showAd( adPosition, isTestMode ) local xPos, yPos local adPosition = "top" -- "top", "bottom" if adPosition == "top" then xPos, yPos = display.screenOriginX, top elseif adPosition == "bottom" then xPos, yPos = display.screenOriginX, bottom end ads:setCurrentProvider("admob") ads.show( "banner", { x = xPos, y = yPos, appId = bannerID, testMode = isTestMode } ) end showAd( "top", testMode )
Remember to put your id in this line of code:
local bannerID = "PUT YOUR ID CODE BETWEEN THESE QUOTES"
Finally, test it on your device. This can’t be tested in the simulator.
How do you disable test mode?
Also, it’s not showing. The main.lua is:
local unusedWidth = display.actualContentWidth - display.contentWidth local unusedHeight = display.actualContentHeight - display.contentHeight local left = 0 - unusedWidth/2 local top = 0 - unusedHeight/2 local right = display.contentWidth + unusedWidth/2 local bottom = display.contentHeight + unusedHeight/2 local bannerID = "ca-app-pub-3054113816306190/1367368068" local testMode = true local ads=require("ads") local function adListener( event ) for k,v in pairs( event ) do print("adListener ", k, v ) -- so you see everything you get end end ads.init( "admob", bannerID, adListener ) ads:setCurrentProvider("admob") ads.load( "admob", { appId = bannerID, testMode = testMode } ) local function showAd( adPosition, isTestMode ) local xPos, yPos local adPosition = "top" -- "top", "bottom" if adPosition == "top" then xPos, yPos = display.screenOriginX, top elseif adPosition == "bottom" then xPos, yPos = display.screenOriginX, bottom end ads:setCurrentProvider("admob") ads.show( "banner", { x = xPos, y = yPos, appId = bannerID, testMode = isTestMode } ) end showAd( "top", testMode )
Given the code above, simply change:
local testMode = true
to
local testMode = false
Rob
Off topic: the icon isn’t showing after it’s installed on a device. It looks just like your avatar, @Rob.
If you’re getting a corona logo as the Icon then you probably don’t have the right Icon files in the folder with your main.lua. Please see:
https://docs.coronalabs.com/guide/distribution/buildSettings/index.html#appicons
And go down to the Android section.
Rob
Well, I put the code which I gave you in a blank project. It ran perfectly (after fixing a missing ‘do’) and showed a banner at the top.
Download this, build it, install it on your device , and run it.
http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/06/admob.zip
If this does not work for you, then I’m stumped. It is either something with your test device or maybe your internet connection… I really don’t know, but this code is solid and now…tested on a Gen 1 Nexus 7.
It worked. Apparently, I didn’t insert the right format of my ID. But it is displaying on top which is blocking some details. How do I get it to display at the bottom?
Read the code I gave you. It has everything you need, spelled out.
The function I wrote: showAd() takes a position parameter.
Well like @roaminggamer said, it appears you are not reading the instructions or even the comments.
See from the code you already have:
local adPosition = “top” – “top”, “bottom”
Now what do you see
?