B4A Library AdMob library

This library requires some configuration. Please see the tutorial: http://www.b4x.com/forum/basic4andr...-admob-tutorial-add-ads-your-application.html

Reference: Basic4android - AdMob

AdMob v2.00 - Based on Google Play Services. This version requires B4A v3.20.

AdMob v1.40 - Add support for SIZE_SMART_BANNER.
These ads will fill the whole available width: https://developers.google.com/mobile-ads-sdk/docs/admob/smart-banners

You can use the following code:
Code: Copy
Adview1.Initialize2("Ad", "xxxxxxxx", AdView1.SIZE_SMART_BANNER)
Dim height As Int
If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
   'phones
   If 100%x > 100%y Then height = 32dip Else height = 50dip
Else
   'tablets
   height = 90dip
End If
Activity.AddView(AdView1, 0dip, 100%y - height, 100%x, height)

See this post for an additional requirement if using google play services v28: https://www.b4x.com/android/forum/threads/admob-library.7301/page-10#post-381519
 

Attachments

Last edited:
Yes - NO update
 
erel, i've just downloaded the 2.0.
does it has new capability to show other type of ad (such as interstitial)?
 
According to Google documentation the minimum version is Android 2.3: https://developers.google.com/mobile-ads-sdk/docs/

I did tested it with Android 2.2 and it worked.
It will not impact Google Play listing (only if you set the minSdkVersion in the manifest editor).

Hello,
I am a little confused by this answer.

You stated above that you tested with 2.2 (API level 8). But in the Admob 2.0 tutorial it says "AdMob library requires Android SDK level 13 or above".

I am asking because currently about 16% of my installs come from devices running APIs less than 13.

Does the new Admod 2.0 library work on devices running 2.2 (API level 8) and above?

Can you explain the apparent contradictions in the statements above? (Tested with 2.2, requires SDK level 13 or above)
Does one mean "to compile" and the other "to run"?

This quote from Google says the Play Services Library version supports the same devices.

While Google says it currently has no plans to stop serving ads through the standalone SDK, you’re probably better off moving to the Google Play services library. The company emphasizes it still supports the same devices and lets you serve ads even on devices that don’t have the Google Play store installed.

Barry.
 
ERROR MANIFEST

Code: Copy
Parsing code.  0.00
Compiling code.  0.02
Compiling layouts code.  0.01
Generating R file.  Error
AndroidManifest.xml:23: error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize')
.
 
ERROR MANIFEST

Code: Copy
Parsing code.  0.00
Compiling code.  0.02
Compiling layouts code.  0.01
Generating R file.  Error
AndroidManifest.xml:23: error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize')
.

How have you edited the manifest?

Using Tools --> Editor?

Code: Copy
AddApplicationText(

 <activity android:name="com.google.ads.AdActivity"

  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>)

It looks like a case of a missing quote or quote in the wrong place.
 
How can i use interstitial ads with this library. i am using google play services in my app
 
that library generates an error if you use it with play services.
Code: Copy
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/google/ads/AdRequest$ErrorCode;
    at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
    at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
    at com.android.dx.command.dexer.Main.processClass(Main.java:685)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
    at com.android.dx.command.dexer.Main.access$600(Main.java:78)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
    at com.android.dx.command.dexer.Main.processOne(Main.java:596)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
    at com.android.dx.command.dexer.Main.run(Main.java:230)
    at com.android.dx.command.dexer.Main.main(Main.java:199)
    at com.android.dx.command.Main.main(Main.java:103)
1 error; aborting
    Optimized dexer failed. Switching to Standard dexer.
 
Then post on that thread... but it looks like you've got Admob (this one) and the Admob Beta library (that one) installed - maybe only have one?
 
Someone else, on that thread, had the same problem as you, have you read the whole of that thread?
 
Hi,
I switched to admob2.0 and it is working fine but I get a weird behaviour, the admob banner is "shacky". I mean it is following the phone orientation, if you look the phone with an orientation perpendicular to the screen, the banner is rectangular. When you look the screen from the rigth side, the banner shifts a bit to the left and takes the shape of a parallelogram ...

I wonder if this is normal but also how do they do this ? Using gyro ?

On my galaxy S3 this effect is obvious...
2014-05-11_111910.jpg


edit : another side effect of admob2.0 is the huge footprint (added around 1Mb compared to the previous version)
eg : torchunlock old admob: 759 kB
admob 2.0: 1636 kB
 
Last edited:
I tried with another application (knigth's ride) which does not use any sensor and I get the same result.
Even playing with the orientation of the screen, shaking it right left when the devise is set horizontal, I can make the ad banner fully shrink.


1.jpg
2.jpg
3.jpg


That's the weirdest thing I saw today, and the ad says "begin to flirt today ...", maybe not with admob 2.0 !!! :eek:

Here is the piece of code I use (the same that with the old version):
Code: Copy
AdView1.Initialize("Ad", "ca-app-pub-mynumber") 'publisher id that you received from AdMob.
    Activity.AddView(AdView1, (100%x - 320dip)/2, 0dip, 320dip, 50dip)
    AdView1.LoadAd 'loads an ad


edit : this shacky behavior is not due to admob2.0... it did exist with the older version...
 
Last edited:
maybe not with admob 2.0 !!!

MAY BE - some other also changed back to the old version, i never updated in case of this problems.
Also i often use LeadBold
 
Back
Top