Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4android > Basic4android Getting started & Tutorials
Documentation Wiki Register Members List Windows Mobile Search Today's Posts Mark Forums Read

Basic4android Getting started & Tutorials Android development starts here. Please do not post questions in this sub-forum.

AdMob Tutorial - Add ads to your application

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-12-2011, 01:17 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 25,807
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default AdMob Tutorial - Add ads to your application

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, 0dip0dip320dip50dip'<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.
Reply With Quote
  #2 (permalink)  
Old 01-12-2011, 04:51 PM
Basic4android Expert
 
Join Date: May 2008
Posts: 789
Default

Update: It worked! So we need to wait about 30 minutes before AdMob active it

-----------------------------

I tried AdMob with my app. The ad banner appeared but AdMob doesn't count it. Otherwise, the status of my app is "Inactive: AdMob has never received an ad request for your site".

I really need some help!
__________________
I'm not good at English, please understand. Thank you.

Last edited by susu : 01-12-2011 at 05:00 PM. Reason: update
Reply With Quote
  #3 (permalink)  
Old 01-12-2011, 05:28 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 25,807
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Yes, the numbers are not updated immediately.
Reply With Quote
  #4 (permalink)  
Old 01-12-2011, 06:01 PM
Basic4android Expert
 
Join Date: May 2008
Posts: 789
Default

But the ad banner is rarely appear on my app (about 1/20). And we can't "earn money by displaying ads in our applications", we only earn when user click the ad banner. I got 0.01$/click, anybody got better?
__________________
I'm not good at English, please understand. Thank you.
Reply With Quote
  #5 (permalink)  
Old 01-12-2011, 06:34 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 25,807
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Quote:
But the ad banner is rarely appear on my app (about 1/20)
I believe that once your application will be more popular it will be served more ads.
Reply With Quote
  #6 (permalink)  
Old 01-12-2011, 10:30 PM
Basic4android Expert
 
Join Date: May 2008
Posts: 789
Default

I'm using emulator and tried to get test ads but I can't find device id in LogCat window. This is what I got:

Quote:
To get test ads on the emulator use AdManager.setTestDevices( new String[] { AdManager.TEST_EMULATOR })
How to fix it?
__________________
I'm not good at English, please understand. Thank you.
Reply With Quote
  #7 (permalink)  
Old 01-13-2011, 06:06 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 25,807
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You should use the constant AdMob.EMULATOR (see the commented lines in the tutorial code).
Reply With Quote
  #8 (permalink)  
Old 01-13-2011, 07:21 AM
Basic4android Expert
 
Join Date: May 2008
Posts: 789
Default

I tried:
Quote:
AdMob.SetTestDevices(AdMob.EMULATOR)
but got error. Can you show me the right code? Thanks.
__________________
I'm not good at English, please understand. Thank you.
Reply With Quote
  #9 (permalink)  
Old 01-13-2011, 07:40 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 25,807
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Here:
Code:
        AdMob.SetTestDevices(Array As String(AdMob.EMULATOR))
Reply With Quote
  #10 (permalink)  
Old 01-13-2011, 07:48 AM
Basic4android Expert
 
Join Date: May 2008
Posts: 789
Default

Another error:

Quote:
AdMob.SetTestDevices(Array As String(AdMob.EMULATOR))
javac 1.6.0_21
src\com\axa\demo\detail.java:188: cannot find symbol
symbol : method SetTestDevices(java.lang.String[])
location: class anywheresoftware.b4a.admobwrapper.AdMob
_admob.SetTestDevices(new String[]{_admob.EMULATOR});
^
1 error
__________________
I'm not good at English, please understand. Thank you.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
GPS tutorial Erel Basic4android Getting started & Tutorials 154 04-30-2013 03:27 PM
SQL Tutorial Erel Tutorials 34 08-20-2012 12:45 PM
AdMob gpsoftuk Bugs & wishlist 2 01-12-2011 01:54 PM
Need SQL tutorial Cableguy Basic4android Updates and Questions 11 11-30-2010 07:03 AM
New GPS tutorial Erel Announcements 2 11-05-2007 11:39 AM


All times are GMT. The time now is 12:16 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0