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: 1,119
  • AdMob.zip
    4.7 KB · Views: 3,010
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
ok thanks, that seemed to work as I got a screen telling me I had to date an older woman, lol :)

It would be nice if this could be included into the standard AdMob library like it is for IOS.
Yes i want to see interstitial on this lib too. only one lib with banner and interstitial
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
Is there any way to create a custom ad size with this library? I am working to implement native ads with admob, but need something to implement the following Java code.

B4X:
AdSize nativeAdSize=new AdSize(250,250);//NativeSize
adView.setAdSize(nativeAdSize);
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
Thank you very much Erel. I had to modify it slightly since I was getting a java error.

Here is my code in context for anyone else who may need to do this.

B4X:
Dim adSize As JavaObject
adSize.InitializeNewInstance("com.google.android.gms.ads.AdSize", Array(250, 250))
nativeAd.Initialize2("nativead","YOUR_AD_ID",adSize)
 

ilan

Expert
Licensed User
Longtime User
what do i need to do?

can someone please help me :(

i have google play service rev29 and downloaded the latest android-support-v4.jar file from android sdk and also added #AdditionalJar: android-support-v4

what else do i need to do?

Screenshot_2016-05-04-23-10-08.png
 
Last edited:

ilan

Expert
Licensed User
Longtime User
ok i downgraded "google play service" to rev24 but what do i need to do to use rev29?
is there any difference for showing ads if i use rev24 instead of rev29?

EDIT: rev27 is also working. (so i am now on rev27)
 
Last edited:

ilan

Expert
Licensed User
Longtime User

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are two things that might be wrong:
1. #AdditionalRes: $AndroidSDK$\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

2. google-play-services.jar in the additional libraries folder.

Those two must be with the same version.

Also check that the manifest editor is configured correctly.
 

ilan

Expert
Licensed User
Longtime User
There are two things that might be wrong:
1. #AdditionalRes: $AndroidSDK$\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

2. google-play-services.jar in the additional libraries folder.

Those two must be with the same version.

Also check that the manifest editor is configured correctly.

so no need to add: #AdditionalJar: android-support-v4

maybe this was the problem? i will try to remove it and compile when i get back to my pc

thanx
 

ilan

Expert
Licensed User
Longtime User
ok i confirm that it is working but i cannot explain why it did not worked yesterday.
i am sure i did everything right. (maybe its magic :p)

thankx :)
 

tufanv

Expert
Licensed User
Longtime User
IS anyone seeing the ads as a blank black screen for interstatials like me =?
 

sorex

Expert
Licensed User
Longtime User
@Erel,

I was having some difficulties here.

But all I got to see was Failed:3.

Is it possible to update the lib so that it exposes the errors as text aswell?

(And while you're at it include the interstitials part aswell plz ;) )

Edit: I don't know if this is a networking error or an issue at admob or something but my ad loads behave like this

failed: 3
received
failed: 3
failed: 3
failed: 3
failed: 3
failed: 3
failed: 3
failed: 3
failed: 3
failed: 3
received


sometimes the refresh timer seems to stop aswell and then nothing appears in the log anymore.



the interstitial at app start always displays fine tho that the weird part of all this.
 
Last edited:

sorex

Expert
Licensed User
Longtime User
It appears that the error means that there was no banner fill.

So no banners left for my region, language or whatever it selects on.
 

aeric

Expert
Licensed User
Longtime User
I just restored my laptop from Windows 10 back to Windows 7 and I need to reinstall B4A and setting up the AdMob library.

I realize the Android Support Library is missing from Android SDK Manager r24.4.1.
Android-Support-Library.png
I am only able to download the Android Support Repository and inside the <sdk>\extras\android only has a folder name m2repository.
Android-Support-Folder.png
So I copy the support folder from <sdk>\extras\android\m2repository\com\android to <sdk>\extras\android
Android-Support-V4.png

For Android support v4, I look for support-v4-19.0.0.jar and copy to <B4A-Additional-Libraries> and rename it as android-support-v4.jar
 
Top