The new AdMob library requires Android SDK level 13 or above. You will need to download it with the SDK Manager and then choose Tools - Configure Paths and choose android.jar from platforms\android-13.
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:
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 GoogleAdMobAdsSdk.jar to the additional libraries path.
Adding AdMob to your application
1. Add a reference to AdMob library.
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) '<b>previously the height was 48dip. Now it is 50dip.
</b>AdView1.LoadAd 'loads an ad
End Sub
Sub Ad_FailedToReceiveAd (ErrorCode As String)
Log("failed: " & ErrorCode)
End Sub
Sub Ad_ReceiveAd
Log("received")
End Sub
Sub Ad_AdScreenDismissed
Log("screen dismissed")
End Sub
-
AdView1 size must be 320dip x 50dip, otherwise it will not display.
The above code puts an ad at the top of the screen.
You can change the Visible property and hide or show the ad.
Manifest editor
The following code should be added to the manifest editor:
Code:
'AdMob
AddApplicationText(
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)
'End of AdMob
Some tips:
- AdMob writes debugging messages to LogCat. However you will not see those messages when LogCat is filtered. Uncheck the "filter" check box and look for these messages.
- On the emulator a test ad should appear instead of a real ad.
- Many times, especially when you start, AdMob will not return any ads. LogCat should display something like:
Code:
failed. No ad to show.
After awhile it should start working. If it doesn't work you should make sure that the package name matches the value defined in "package url" in AdMob site.