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:
B4X:
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

  • AdMob_old.zip
    4.3 KB · Views: 974
  • AdMob.zip
    4.7 KB · Views: 2,858
Last edited:

Inman

Well-Known Member
Licensed User
Longtime User
Hey Bill, any chance you updated this library to add smart banners?
 

corwin42

Expert
Licensed User
Longtime User
Hello Erel,

can you please post the source of Version 1.36?

I have a problem in my weather app that after some time it produces cpu load even if the app is not visible. I think it has something to do with the ads. I'm currently trying a version without ads and it seems the cpu load does not appear.

I will try to use StopLoading() method to stop loading of ads on activity_pause and see if the cpu load will not appear anymore.
 

MaxApps

Active Member
Licensed User
Longtime User
Never mind... I found the problem.
The config of B4A was pointing to a Lib dir, that I was not using.


Hi

I have downloaded the latest version of the library file and the latest SDK from google admob.
But I cannot see the initialize2

I have refreshed and even installed a brand new version of B4A (2.02) and still no initialize2
Any ideas?

Kind regards
Jakob
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
I have a problem in my weather app that after some time it produces cpu load even if the app is not visible.

Ok, forget it. I had an old GoogleAdMobSDK.jar (4.3.1) in use which had the problem. Updated to 6.1.0 and everything is fine now.
 

corwin42

Expert
Licensed User
Longtime User
Ok, forget it. I had an old GoogleAdMobSDK.jar (4.3.1) in use which had the problem. Updated to 6.1.0 and everything is fine now.

I was wrong. The High CPU load problem still exists in the latest AdMob SDK. I had to add the following to "Activity_Pause" to solve it completely:

B4X:
Dim r As Reflector
r.Target = AdMobView
r.RunMethod("stopLoading")
AdMobView.RemoveView
r.RunMethod("destroy")
AdMobView = Null
 

LoveB4A

New Member
Licensed User
Longtime User
Having a problem. I downloaded AdMob B4A library.

But when I went to unzip it got the message:

The Compressed (zip) is invalid or Corrupted?

what is wrong.
 

pluton

Active Member
Licensed User
Longtime User
Having a problem. I downloaded AdMob B4A library.
But when I went to unzip it got the message:
The Compressed (zip) is invalid or Corrupted?
what is wrong.

Just download it again. I just download and test it. It extracts fine
 

Inman

Well-Known Member
Licensed User
Longtime User
Erel, if you are free, could you please add the Admob interstitial ads (and if possible smartbanners) to the Admob library?
 

NJDude

Expert
Licensed User
Longtime User
I think the smart banners differenciate between phones and tablets, in other words, the code you posted works only on phones, for tablets, the values should be:
B4X:
If 100%x > 100%y Then height = 50dip Else height = 90dip
However, the line above works fine on phones and tablets, the only problem is that on phones you will have empty space on the top or bottom of the ad or all around depending on the orientation.
 

NJDude

Expert
Licensed User
Longtime User
Google documentation is not clear about this. Where have you seen a reference to a height of 90?

Those values are on the table on the link you provided, for example:
B4X:
800x90    Android tablets in Portrait
When I first installed the sample code on one of my tabs didn't work, after changing the values then I saw the ads.
 

NJDude

Expert
Licensed User
Longtime User
I think this should do it:
B4X:
If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
   
    'phones
    If 100%x > 100%y Then height = 32dip Else height = 50dip
         
Else
            
    'tablets
    If 100%x > 100%y Then height = 50dip Else height = 90dip

End If
 
Top