Got Admob working for Android :)

170 replies [Last post]
kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

EDIT: Added HoneyComb UA fix (check android ad htmls
EDIT: Change made for latest corona.

So, I saw alot of complaints about this and people really strugling with it. I finally found a bit of time looking at it.

I tested this on Corona 243, and daily 317. Other versions may have issues I don't know.

EDIT: This has developed to a completely working solution on all devices! Instead of leaving the code fragmented across posts I've moved EVERYTHING you need to this first post:

Tested on Corona upto latest daily, and also including daily 319 for android.

Step 1)

You MUST add the internet permissions to the build.settings file. For the sake of completness here's a build.settings file that you can drop in place:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
settings = {
        orientation =
        {
                default = "portrait",
        supported =
        {
                "portrait",
        },
    },
    androidPermissions =
    {
            "android.permission.INTERNET",
            "android.permission.ACCESS_NETWORK_STATE"
    },
}

Step 2) Sign up for admob and create a new 'site'. Pick Android to get an android id - you'll use this in step 3. Create a second site and pick 'iphone' to get an apple id.

Ignore the sdk download, as you can't use it with corona. Edit the site and set the refresh rate to 20 seconds (this ensures an ad is refreshed on their side ready for when you http refresh your page).

Step 3) Create the following files from the code below:

main.lua - add this code to your main.lua and use DisplayAd(delay) to show and ad after 'delay' milliseconds. Use RemoveAd(delay) to remove it after delay milliseconds.

android_ad.html - This is the html file for showing ads on all android devices with zoom level <= 1.5. Change the admob id to the one you received when you created the ''site' in admob.

android_ad15.html - This is the html file for showing ads on all android devices with a zoom level > 1.5. Change the admob id to the one you received when you created the ''site' in admob. It should be the same one as above.

apple_ad.html - This handled ALL apple devices. I suggest you create a SECOND site in admob and use a seperate id for this, so you can see how much revenue you are generating from apple vs android.

You should also change the 'test:' line to 'false' when you want to see real ads.

-- main.lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
local adSpace
local isAndroid = "Android" == system.getInfo("platformName")
 
function showAd_Android(event)
        -- Is the url a remote call?
        if string.find(event.url, "android_ad.html", 1, false) or string.find(event.url, "android_ad15.html", 1, false) then
                return true
        else
                system.openURL(string.gsub (event.url, "Corona:", ""))
               -- Refresh ad
               RemoveAd(0)
               DisplayAd(0)
                return true
        end
end
 
local function showAd_Apple(event)
     -- Is the url a remote call?
     if string.find(event.url, "http://", 1, false) == 1 then
          -- Is it a call to the admob server?
          if string.find(event.url, "c.admob.com", 1, false) == nil then
               adSpace.url = event.url
          else
               -- an actual click on an ad, so open in Safari
               system.openURL(event.url)
               -- Refresh ad
               RemoveAd(0)
               DisplayAd(0)
          end
     else
          -- Feb 1, 2011: if using the old version of this code, remove the
          -- following line:
          -- adSpace.url = event.url
          -- and put in this line instead:
          return true
     end
end
 
function DisplayAd(t)
        native.cancelWebPopup()
        timer.performWithDelay(t, function()
                        local adfile = "apple_ad.html"
                        local sizeX = 320
                        local sizeY = 48
                        local scale = 1/display.contentScaleY
 
                        if isAndroid then
                                if scale > 1.5 then 
                                        adfile = "android_ad15.html"
                                        sizeX = sizeX*(1.5/scale) + 1
                                        sizeY = sizeY*(1.5/scale) + 1
                                else
                                        adfile = "android_ad.html"
                                end
                                adSpace = native.showWebPopup((display.contentWidth - sizeX)/2, display.contentHeight - display.screenOriginY - sizeY, sizeX, sizeY, adfile, {baseUrl = system.ResourceDirectory, hasBackground = false, urlRequest = showAd_Android})
                        elseif system.getInfo( "environment" ) == "simulator" then
                                adSpace = display.newRect( (display.contentWidth - sizeX)/2, display.contentHeight - display.screenOriginY - sizeY, sizeX, sizeY )
                                display.getCurrentStage():insert(adSpace, false)
                        else
                                if scale > 1.5 then 
                                        sizeX = sizeX*(1.5/scale) + 1
                                        sizeY = sizeY*(1.5/scale) + 1
                                end
                                adSpace = native.showWebPopup((display.contentWidth - sizeX)/2, display.contentHeight - display.screenOriginY - sizeY, sizeX, sizeY, adfile, {baseUrl = system.ResourceDirectory, hasBackground = false, urlRequest = showAd_Apple})
                        end
                end
        )
end
 
function RemoveAd(t)
        timer.performWithDelay(t, native.cancelWebPopup)
        timer.performWithDelay(t, function() adSpace:removeSelf() end)
end

## android_ad.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
 
<html lang="en">
<head>
<meta name="viewport" content="width=320; user-scalable=0;"/>
<META HTTP-EQUIV="Refresh" CONTENT="30">
        <title>ad</title>
</head>
<body style="margin:0; padding:0;">
        <script type="text/javascript">
        var admob_vars = {
         pubid: '000000000000000', // publisher id - FILL IN YOUR OWN ID HERE!!
         bgcolor: '000000', // background color (hex)
         text: 'FFFFFF', // font-color (hex)
         ama: false, // set to true and retain comma for the AdMob Adaptive Ad Unit, a special ad type designed for PC sites accessed from the iPhone.  More info: http://developer.admob.com/wiki/IPhone#Web_Integration
         test: false // test mode, set to false to receive live ads
        };
        </script>
        <script type="text/javascript">
                var userAgentTemp = navigator.userAgent;
            if (!(RegExp("Android (1|2).").test(userAgentTemp))) {
                navigator = {}
                    if (userAgentTemp.search(/Android/) != -1) {
                                navigator.userAgent = userAgentTemp.replace(/Android 3[\.\d]*/, "Android 2.3.3");
                        } else {
                                navigator.userAgent = userAgentTemp + "; Android 2.3.3";
                };
            };
        </script>
        <script type="text/javascript" src="http://mmv.admob.com/static/iphone/iadmob.js"></script>
    <script type="text/javascript">
        _admob.gotourl = function (V, W) {
                        document.location = "Corona:" + V;
                        return true;
        };
        </script>
</body>
</html>

## android_ad15.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
 
<html lang="en">
<head>
<meta name="viewport" content="width=320; initial-scale=1.5; minimum-scale=1.5; maximum-scale=1.5; user-scalable=0;"/>
<META HTTP-EQUIV="Refresh" CONTENT="30">
        <title>ad</title>
</head>
<body style="margin:0; padding:0;">
        <script type="text/javascript">
        var admob_vars = {
         pubid: '000000000000000', // publisher id - FILL IN YOUR OWN ID HERE!!
         bgcolor: '000000', // background color (hex)
         text: 'FFFFFF', // font-color (hex)
         ama: false, // set to true and retain comma for the AdMob Adaptive Ad Unit, a special ad type designed for PC sites accessed from the iPhone.  More info: http://developer.admob.com/wiki/IPhone#Web_Integration
         test: false // test mode, set to false to receive live ads
        };
        </script>
        <script type="text/javascript">
                var userAgentTemp = navigator.userAgent;
            if (!(RegExp("Android (1|2).").test(userAgentTemp))) {
                navigator = {}
                    if (userAgentTemp.search(/Android/) != -1) {
                                navigator.userAgent = userAgentTemp.replace(/Android 3[\.\d]*/, "Android 2.3.3");
                        } else {
                                navigator.userAgent = userAgentTemp + "; Android 2.3.3";
                };
            };
        </script>
        <script type="text/javascript" src="http://mmv.admob.com/static/iphone/iadmob.js"></script>
    <script type="text/javascript">
        _admob.gotourl = function (V, W) {
                        document.location = "Corona:" + V;
                        return true;
        };
        </script>
</body>
</html>

## apple_ad.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
 
<html lang="en">
<head>
<meta name="viewport" content="width=320; user-scalable=0;"/>
<META HTTP-EQUIV="Refresh" CONTENT="30">
        <title>ad</title>
</head>
<body style="margin:0; padding:0;">
        <script type="text/javascript">
        var admob_vars = {
         pubid: '000000000000000', // publisher id - FILL IN YOUR OWN ID HERE!!
         bgcolor: '000000', // background color (hex)
         text: 'FFFFFF', // font-color (hex)
         test: false // test mode, set to false to receive live ads
        };
        </script>
        <script type="text/javascript" src="http://mmv.admob.com/static/iphone/iadmob.js"></script>
</body>
</html>

Replies

rxmarccall
User offline. Last seen 5 years 22 weeks ago. Offline
Joined: 18 Jan 2011

Thanks for the tutorial, i will be giving it a shot once my app gets close to release. ill report how it goes.

maxbarrow
User offline. Last seen 8 years 46 weeks ago. Offline
Joined: 16 Nov 2010

Thanks dude this seems to have nailed it. Now if only corona would fix multi-touch (only two touches allowed at once on android) , openAL and most of the other stuff that doesnt work on android!

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

Multi touch on android is a bit of a mess tho actually. Different devices support different things in their driver. Some only handle two touches and anything more is a 'palm' touch.

AlenB
User offline. Last seen 6 years 48 weeks ago. Offline
Joined: 29 Sep 2010

Hi kam187,

it works .. thx for sharing..
it opens in a new webpopup!

Did you use it in any android app?

bruno_gallien
User offline. Last seen 7 years 31 weeks ago. Offline
Joined: 15 Sep 2010

It works fine but it is very, very slow.
And the function is never called.

Bruno from http://blueglutton.com

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

alen.brkicic8: Not yet. I was going to add it to the lite version of Walkabout but decided not to just yet.

bruno_gallien: It works fine here, and definatly calls the function. What version of corona do you use? and which OS version of android do you build for?

bruno_gallien
User offline. Last seen 7 years 31 weeks ago. Offline
Joined: 15 Sep 2010

Hi,
I use the last daily build and I build for 2.2 with a 2.3.2 phone.

Bruno from http://blueglutton.com

bruno_gallien
User offline. Last seen 7 years 31 weeks ago. Offline
Joined: 15 Sep 2010

My bad I discovered I had a typo.
But now the function is called even if i don't click on the banner and in addition the banner is not appearing.

Bruno from http://blueglutton.com

khanh.dq
User offline. Last seen 4 weeks 1 day ago. Offline
Joined: 17 Sep 2010

Hi bruno_gallien, what is your device name? Could you post your project here?

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

Remember the ad.html has to be called exactly that. This line here checks if its loading the ad.html or its a click:

if not string.find(event.url, "ad.html", 1, false) then

If you change the name of your ad.html you need to change this string too. If you renamed the file it will think there was a click as soon as the ad loads.

bruno_gallien
User offline. Last seen 7 years 31 weeks ago. Offline
Joined: 15 Sep 2010

In fact there's something I don't understand : should the function be called only if I click or is it also used to get the banner ?

Bruno from http://blueglutton.com

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

Its called when the page loads (ad.html) to display the banner. and ALSO if its clicked.

That line of code checks if the url is the ad page. This is how it knows if the ad page is loading, or its been clicked.

You should use the code template I posted. If you modified it or removed/renamed the file it wont work.

bruno_gallien
User offline. Last seen 7 years 31 weeks ago. Offline
Joined: 15 Sep 2010

Ok so I messed up somewhere because it was loading the banner.

Bruno from http://blueglutton.com

Daniel W.
User offline. Last seen 1 year 34 weeks ago. Offline
Joined: 13 Jan 2011

I got the ad working, but it seems very slow. It looks like bruno_gallien is experiencing the same problem. Any ideas as to why it's slow?

joshdobbs
User offline. Last seen 41 weeks 6 days ago. Offline
Joined: 25 Jan 2011

Thanks for the example...i got it working but now im wondering if there is a way to remove the banner or if theres a way to add it to a group.

joshdobbs
User offline. Last seen 41 weeks 6 days ago. Offline
Joined: 25 Jan 2011

I figured out a way to remove the ad banner....it's probably not the best way but it works for me.

In addition to ad.html i also have a file named noad.html which is the same file provided here(http://www.ludicroussoftware.com/corona/admob-ad-support-in-corona/) that has a bunch of x's instead of my actual pubid. it's more of a hack but it works.

Daniel W.
User offline. Last seen 1 year 34 weeks ago. Offline
Joined: 13 Jan 2011

What's your fill rate with AdMob?

joshdobbs
User offline. Last seen 41 weeks 6 days ago. Offline
Joined: 25 Jan 2011

My fill rate for the last 30 days is 89%. it's 56% for the lats 90 days and its 89% for the last 2 years. Currently all of my apps are for Android.

Daniel W.
User offline. Last seen 1 year 34 weeks ago. Offline
Joined: 13 Jan 2011

Was your fill rate low when you first started with admob? I just placed ads in my app last week and my fill rate is at 30%. With your high fill rate, I wonder if it just takes a little bit to get the fill rate up.

maxbarrow
User offline. Last seen 8 years 46 weeks ago. Offline
Joined: 16 Nov 2010

Fill rates in my none corona apps with correct admob sdk are around 90% but with the web hack its about 30%.

I think it maybe because Admob can search your iphone app page on itunes and target ads to the type of app, where the web app is generic and cant be monitored correctly.

Hopefully Corona will have a proper integration one day;(

mr_x408
User offline. Last seen 8 years 27 weeks ago. Offline
Joined: 8 Feb 2011

For the life of me I can't get this to work nothing pops up mabe its my admob account or something i dontknow but i think ill just wait until its officially supported

admin55
User offline. Last seen 5 years 2 days ago. Offline
Joined: 27 Mar 2011

EDIT: Got it working. My game is on landscape mode, so I needed to change the x,y coords, plus my phone was on airplane mode lol.

coderebelbase
User offline. Last seen 3 years 39 weeks ago. Offline
Joined: 1 Feb 2010

This doesn't work on Android 3.0. I copied the files and input my admob publisher id. Nothing.

khanh.dq
User offline. Last seen 4 weeks 1 day ago. Offline
Joined: 17 Sep 2010

MOST WANTED:
build-in ads support and android in-game purchase, openfeint :D

holmes2870
User offline. Last seen 7 years 6 weeks ago. Offline
Joined: 3 Feb 2011

I tried this code on my iphone and my ads aren't showing, I guess there's no fill at the moment?

Then I tested the other setup from the link and then the ad didn't popup, instead the ad opened in the little adbanner... wonder how to fix that?

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

Got this working on android and iOS. I'll update in detail later. The above code works fine for android on all devices - except 3.0.

The original code from http://www.ludicroussoftware.com/tag/corona/ works fine on iOS, except you should change this line:

to:

so that the advert increases in size on iPad.

You should also add this to the ad.html to refresh the ads:

This would refresh every 30 seconds. On the admob server set the refresh to less than this. I use 20 seconds.

mantic1
User offline. Last seen 6 years 48 weeks ago. Offline
Joined: 20 Jan 2011

To what? From what? :(

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

Wierd! I pasted it but it didnt post.

Change this:

[All code moved to first post]

holmes2870
User offline. Last seen 7 years 6 weeks ago. Offline
Joined: 3 Feb 2011

I've tried this code now and it works fine, but recently it have come to my knowledge from some forums that it is possible to change the publisher id inside the html when you have a jailbroken device.

I wonder if it is possible to add the publisher id inside the build.settings and call it from there or if the entire adMob code can be embedded inside a lua file?

I don't have the skills to pull this off but maybe someone with more experience could pull this off and share the code?

Thanks.
David

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

A little update:

Currently admob aren't serving ads to android 3+ over this interface, and this is why tablets don't show ads. You should check in your code if the current version is > 3 and disable the webpopup:

Something like this:

1
2
3
4
5
6
7
ads = true
if system.getInfo( "platformName" ) == "Android" then
        local AndroidVersion = string.sub (system.getInfo( "platformVersion" ), 1, 1)
        if tonumber(AndroidVersion) < 3 then
                ads = false
        end
end

There is a way to get around this, so if you have a tablet centric app and desperately need ads on 3.0+ then give me a shout on irc and i'll help you out.

Another note. The webpopup will only zoom the ad 1.5 at the most. So to make sure your web popup isnt too big you need to do this:

1
2
3
4
5
6
7
8
9
10
                        local sizeX = 320
                        local sizeY = 48
                        local scale = 1/display.contentScaleY
                                if scale > 1.5 then 
                                        adfile = "android_ad15.html"
                                        sizeX = sizeX*(1.5/scale) + 1
                                        sizeY = sizeY*(1.5/scale) + 1
                                else
                                        adfile = "android_ad.html"
                                end

And then make your webpopup sizeX by sizeY.

gibsonpa
User offline. Last seen 5 years 1 week ago. Offline
Joined: 19 Feb 2011

kam187,

I almost have this working...but am not sure what the difference is between the android_ad.html and android_ad15.html? Do I need to open android_ad.html and make a few tweaks to the html and "save as" ad15?

Also, is there any harm in serving live ads during testing my app? I had the html parm "test:true" for awhile...but then switched to "test:false" and got live ads...being new to the whole ad thing...not sure if serving live ads is bad during testing.

Thanks for all the help,
Paul

droidresearch
User offline. Last seen 4 years 15 weeks ago. Offline
Joined: 25 May 2011

Hi Kam,

Thanks for sharing useful info.

If we are doing this for Android, shouldn't this line be changed:

src="http://mmv.admob.com/static/iphone/iadmob.js"

It is referring iphone/iadmob.js .

Should it not be changed to the android url instead?

Where can I get the correct url for android?

Again, thanks for sharing, appreciate it very much!

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

The same script is used for iPhone and android. There isn't a seperate URL for android. Admob check for an android useragent and switch to android ads automatically.

gibsonpa
User offline. Last seen 5 years 1 week ago. Offline
Joined: 19 Feb 2011

Thanks for the help kam187. Got it working using your method! App is in the market and adds are working really well. Really on 2 issues (probably on my part). I get around 85% fill rate...guess some ads are not served up for some reason...and the webpopup shifts right on the screen about 100 pixels when first opened on the game screen.

Besides those little things...working great. Thanks for sharing! BTW, can't wait for your base2 blog update...loved reading what you had so far! Will for sure read your suspend/resume writeup when its posted.

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

The fill rate is just admob not having enough ads to send you. My fill rate is about the same. If the ads weren't displaying for some reason admob just wouldn't count them :)

With regards to the ad jumping around, you need to use the check in my last post. To make it clearer here's all the code in one shot!

Use DisplayAd(delay) to display an ad in 'delay' seconds.
Use RemoveAd(delay) to remove an ad in 'delay' seconds.

This code will draw a white rect in place of the ad on the simulator so you can see where it will be :)

[All code moved to first post]

gibsonpa
User offline. Last seen 5 years 1 week ago. Offline
Joined: 19 Feb 2011

kam187,

You are the best!! That is perfect. Without your help, I could not have gotten ads working in my game!

I just updated my game (Color Confusion http://bit.ly/kSX8go) last night for some minor bugs and a few tweaks based on user feedback.

In my next update, I will make the 1.5 tweaks.

BTW, we have installed your game on all our tablets (Asus Transformer x2 and Viewsonic GTab)...everyone loves playing it!

zyg@accessport.cn
User offline. Last seen 8 years 15 weeks ago. Offline
Joined: 24 Mar 2011

when i change ad.html "test:true" to "test:false", the webpopup no longer show up. why? please help,thanks.

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

You need to add the permissions from the first post if you're on android. Also you need to setup admob, and you're id. I'll update the first post with all the info!

EDIT: first post updated with all info.

BenBressington
User offline. Last seen 5 years 51 weeks ago. Offline
Joined: 7 Jun 2011

Having trouble with this...followed all instructions
no errors in console but nothing appears in simulator in test mode
no white rectangle nada....

zyg@accessport.cn
User offline. Last seen 8 years 15 weeks ago. Offline
Joined: 24 Mar 2011

hi kam187,thanks for your reply.I have added the permissions on android,and i have had a admob publisher ID.The status now is active.when test is true in ad.html,it work fine,there is a test ad show up.but when i change the test is false in ad.html,nothing display.Look forward to your reply.Thanks.

holmes2870
User offline. Last seen 7 years 6 weeks ago. Offline
Joined: 3 Feb 2011

@kam187

I wonder if there's a way to store the publisher id in the lua code instead of the ad.html file?

Since there are users with Jailbreaked devices that can change the Publisher Id with their own and steal our revenue, I've seen that on many forums that a lot of people does that to make a few extra $.

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

benvsweb - Do you ever call DisaplyAd(0) ? You need to call that to show the ad. The webpopup is ALWASY on top, so just as a test call DisplayAd(0) at the begining of your main.lua. The ad should show at the bottom.

zyg@accessport.cn - do you run any ad blocker on your phone? Check a game like angry birds and see if you see any ads in it. Also go to whatsmyua.com in your browser on your phone and verify it says 'Android 2.x.y' (where x and y can be anything)

holmes2870 - Yes it would be possible to embed the id inside the lua code but after thinking about it, I came to the conclusion there's very little point - the idea of editing the id makes no sense to me at all:

There's very little advantage of someone editing your id out of your app on their own device. What would be the point? The ads displayed would be linked to their account - sure, but what would they really gain?

If they wanted to display ads for their account on their device and get impressions they could just run their own app :/ If they want to click their own ads to gain revenue they could do that in their own game too. Doing either of these wouldn't work for very long anyway since all the ads would show the same IP address and admob would probably suspend the account pretty quick.

At first sight what you're saying sounds really bad, but think it through a little and its totally pointless for anyone to do that. If you're saying people edit out your id and release a pirate copy of your game - 99.999% of games with ads are free. Why would anyone want to download a copy of a free game from an untrusted source when they can get it direct from the App Store or Android market?

In any case, if for some crazy reason someone did want to edit you're id, the lua code itself is not hard to edit, even once the game is compiled.

I'd be interested to see where you read this and what discussion it led to? It sounds more like FUD to me.

BenBressington
User offline. Last seen 5 years 51 weeks ago. Offline
Joined: 7 Jun 2011

kam187:
i used the main lua code you posted along with the .html codes
you supplied. But I see no white rectangle at all in the corona simulator?

do I need to add anything other than the code you have in the
first post?

thanks

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

yes, when you want the ads to show u need to call:

DisaplyAd(0)

And to remove them

RemoveAd(0)

For example. You may not want ads on your menu screen. But when the game starts u want ads. So call DisplayAd(0) at that point.
Maybe you want the ads to start in 1 second so then use DisplayAd(1000).

Then when the game ends and you go back to the menu you might want to call RemoveAds(0) to remove them again :)

BenBressington
User offline. Last seen 5 years 51 weeks ago. Offline
Joined: 7 Jun 2011

Thank you Kam works perfectly :)

coderebelbase
User offline. Last seen 3 years 39 weeks ago. Offline
Joined: 1 Feb 2010

Any ideas why it wouldn't work on Android 3.0? CoronaSDK webpopup issue?

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

Its not the webpopup. I have it working on 3.0 but I don't think its wise for _everyone_ to use this method. If you have a tablet centric app and realllllly need it you can find me on irc for the solution :P

coderebelbase
User offline. Last seen 3 years 39 weeks ago. Offline
Joined: 1 Feb 2010

@kam187

Nice! Why do you think this?

kam187
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 10 Sep 2010

Rather not say here :)

droidresearch
User offline. Last seen 4 years 15 weeks ago. Offline
Joined: 25 May 2011

Dear Kam,

As usual you are great!

I had to add this extra line:

local isAndroid = "Android" == system.getInfo("platformName");

just before the function DisplayAd(t)

to make it work.

I wrote a simple physics-based game (shooting aliens with particles) and included your code. This is on Windows and Android. Tested it on my Galaxy Tab. The ad displayed fine and when I touched on it, the webpopup shows full screen (the Admob Test Page). Then, when I touched on the return button on my galaxy tab, I expected it to return to the game, but instead, it shows a black screen. After 5 seconds, it Force Closes with the usual Android Force Close message (The app ... has stopped unexpectedly. Please try again.). Since this happens on the actual device, I am not able to debug it. The Corona Simulator does not support Web Pop Ups. I am at a loss on how to debug this issue.

Any advice would be much appreciated :)

And thanks again for your willingness to share your knowledge!

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.