Corona SDK : Integrate Admob Banner for Android

Corona SDK : Integrate Admob Banner for Android

Test on:
- Mac OS X El Capitan
- Asus Zenfone 4.5
- Android SDK
- Corona SDK [download] https://coronalabs.com/

[Pre-require]
If you don't have your project please create simple test project from this link first

Corona SDK : Getting start for Android
http://gamedevtodied.blogspot.com/2016/04/corona-sdk-getting-start-for-android.html

[Admob implement]
1. Open your "main.lua" and add this code after last line.

[start - code]
-- Create a text object to display ad status
local statusText = display.newText( "ADS STATUS", 0, 0, native.systemFontBold, 22 )
statusText:setTextColor( 255 )
--statusText:setReferencePoint( display.CenterReferencePoint )
statusText.x, statusText.y = display.contentWidth * 0.5, 160

-- admob implement
local ads = require( "ads" )

local function adListener( event )
    if ( event.isError ) then
        -- Failed to receive an ad
        statusText.Text = event.isError;
    end
end

ads.init( "admob", "ca-app-pub-3940256099942544/6300978111", adListener )

-- Optional table containing targeting parameters
local targetingParams = { tagForChildDirectedTreatment = true }

ads.show( "banner", { x=0, y=0, targetingOptions=targetingParams} )
[end - code]

Let's see sample image, your code similar to be like this.


2. Open your "build.settings" and add this code to your file

[start - code]
    --
    -- Admob Plugin
    --
    plugins =
    {
        ["plugin.google.play.services"] =
        {
            publisherId = "com.coronalabs",
            supportedPlatforms = { iphone=false, android=true }
        },

    },
[end - code]


Let's see sample image, your code similar to be like this.


and don't forget to check in this file having below code included?, because your ads need permission for android device to receive ads.

[start - code]
--
-- Android Section
--
android =
{
usesPermissions =
{
"android.permission.INTERNET",
                        "android.permission.ACCESS_NETWORK_STATE",
},
},
[end - code]

[Test Run]
1. Goto Corona Simulator, "File > Build > Android..."


2. Build setting dialog for android will open, check your detail and edit "Package" as you want and "After Build" choose "Copy to device and launch" (It's maybe not launch but success installed).


3. Click "Build" and wait a while for processing build and install on android device.



4. When it's completed, you should see dialog "Device Installation Complete" (It's maybe not launch on device, take a look by yourself).


5. Take a look on your android device, (find grey small "icon") and launch it.


[Free sample source code]
Apk file: 
Source code: 

It's work :)

Comments