This is a mirror of official site: http://jasper-net.blogspot.com/

AdMob Tutorial - Add ads to your application

| Thursday, April 28, 2011
Edit: The AdMob SDK has changed and is not fully backwards compatible. The tutorial was updated accordingly.

Using the new AdMob library you can earn money by displaying ads in your applications. 

Installing AdMob libraries:

1. Go to AdMob - Register and register to AdMob.
2. Add an application:

admob_3.png

The url can be a placeholder for a future application.

3. After creating the application you should see a screen with your "Publisher ID" and a link to "get publisher code".
Later you will need to enter your publisher id in the program code. Now you should download AdMob SDK by pressing on "get publisher code".
You will download a zip file with a name similar to: GoogleAdMobAdsSdk-4.0.4.zip. 
Inside the zip there is a folder with the same name. Inside this folder you will find the required jar file (GoogleAdMobAdsSdk-x.x.x.jar).
Note that you may have problems extracting the whole zip file because it contains a folder and a file with the same name. The solution is to just drag the required file.
Rename the jar file and change its name to GoogleAdMobAdsSdk.jar (removing the specific version suffix).

4. Download AdMob B4A library.
You should copy all files to the additional libraries path.

5. Copy GoogleAdMobAdsSdkAndroid.jar to the additional libraries path.

Adding AdMob to your application

1. Add a reference to AdMob and GoogleAdMobAdsSdk libraries.
2. Typical code should look like:

Code:
Sub Process_Globals
    
End Sub

Sub Globals
    Dim AdView1 As AdView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    AdView1.Initialize("Ad", "YourPublisherId") 'publisher id that you received from AdMob.
    Activity.AddView(AdView1, 0dip, 0dip, 320dip, 50dip) 'previously the height was 48dip. Now it is 50dip.
    AdView1.LoadAd 'loads an ad
End Sub

'debugging only:
Sub Ad_FailedToReceiveAd (ErrorCode As String)
    Log("failed: " & ErrorCode)
End Sub
Sub Ad_ReceiveAd

Posted via email from Jasper-net

0 comments: