Hey Guys,
A little while back I got full screen interstitial ads working in my game "The Bird Game" (link:
http://forum.thegamecreators.com/?m=forum_view&t=210899&b=48 ) in AppGameKit Tier 1. I've decided to make a tutorial to show how to get them working on Android and iOS.
Interstitial Ads For Android:
This tutorial assumes you know how to build the agk player using Eclipse!
Open the AppGameKit Player (or if your building your final app open that project) in Eclipse
At the top of Eclipse, click on the "Android SDK Manager" Button. The Android SDK Manager window will come up (it might auto select some things, so you might want to hit "deselect all"), go all the way down to extras. Check the box that's labeled "Google Play services" and then hit install packages.
Photo:
Once the package has been installed, exit the Android SDK Manager.
Right click on the project and go to the bottom and select "Properties".
Photo:
The properties window should open. On the left panel select "Java Build Path" and then select the "Libraries" tab. On the right side of the window click the "Add External JARs...." button. A navigation window should pop-up, locate the "google-play-services_lib.jar" inside your Android SDK directory (By default it should be located in "C:\Program Files (x86)\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\bin"). Select the file and then hit "Ok" on the properties window.
Photo:
Now, Go into the AndroidManifest.xml and go towards the bottom. Just above the line that says "</application>" add the following two lines:
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Finally, replace the AGKHelper.java file with the one that's attached to this post.
For using the ads in tier 1 go to the section of this tutorial titled "Calling Interstitial Ads From Tier 1".
Interstitial Ads For iOS:
Go here
https://developers.google.com/mobile-ads-sdk/download#downloadios and download the latest version of the Admob SDK for iOS.
Open the AppGameKit Player (or if your building your final app open that project) in Xcode.
On the left panel right click the "Classes" folder and click "Add File To..."
Photo:
Navigate to the Google Admob SDK download, and select all the files in the folder and click the "Add" button.
Photo:
Replace the UntitledViewController.h and the UntitledViewController.m with the ones attached to this post.
Inside of the UntitledViewController.m locate the following line:
NSString *MY_INTERSTITIAL_UNIT_ID = @"INSERT_ADMOB_UNIT_ID_HERE";
Replace where it says "INSERT_ADMOB_UNIT_ID_HERE" with your Admob unit id.
For using the ads in tier 1 go to the section of this tutorial titled "Calling Interstitial Ads From Tier 1".
Calling Interstitial Ads From Tier 1
Use the following AppGameKit Tier 1 functions to use interstitial ads:
Function InterstitialSetup( key$ as string )
Select GetPlatform( )
Case "android":
SetAdMobDetails( key$ )
CreateAdvertEx( 0,1,0,0,1,0 )
Endcase
Case "ios":
Endcase
Endselect
Endfunction
Function InterstitialShowAd( )
Select GetPlatform( )
Case "android":
SetAdvertVisible( 1 )
Endcase
Case "ios":
SetMemblockInt( 2,0,1 )
Endcase
Endselect
Endfunction
Function InterstitialLoadAd( )
Select GetPlatform( )
Case "android":
RequestAdvertRefresh( )
Endcase
Case "ios":
SetMemblockInt( 2,4,1 )
Endcase
Endselect
Endfunction
Function InterstitialSetup( key$ as string )
Select GetPlatform( )
Case "android":
SetAdMobDetails( key$ )
CreateAdvertEx( 0,1,0,0,1,0 )
Endcase
Case "ios":
Endcase
Endselect
Endfunction
Function GetPlatform( )
device$ = Lower( GetDeviceName( ) )
if Left( device$,3 ) = "ios" then platform$ = "ios"
if Left( device$,7 ) = "android" or GetMemblockExists( 1 ) then platform$ = "android"
Endfunction platform$
"InterstitialSetup( key$ )" - This function will setup the interstitial ad system, and begin loading the first ad. Add this function towards the start of your app. For the input use your
Android Admob interstitial unit ID.
NOTE: The iOS unit ID gets hardcoded into the UntitiledViewController.m see above iOS tutorial for instructions
"InterstitialLoadAd( )" - This will call for a new ad to be loaded.
NOTE: It is important to call this function every loop. Don't worry, if a new ad is already being loaded the function call is ignored, but it is still important to call every loop.
"InterstitialShowAd( )" - This will show the loaded ad. If an ad has not been loaded yet, the call will be ignored.
If for some reason you have trouble getting it working, or there is some confusion with my instructions let me know.
Sean