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: 976
  • AdMob.zip
    4.7 KB · Views: 2,860
Last edited:

nad

Active Member
Licensed User
Longtime User
I love smartbanners !!

Thanks a million for the update Erel. You are awesome!
(not that we did not know already :) )
 

pleskina

Member
Licensed User
Longtime User
Hello, I am sorry to revive this post, but as I never tried to use Admob or AdMob library so far, I must ask for some help.

I did all by-the-book, installed the library, including Google's, edited the manifest using manifest editor (I saw AdMob was working because it reminded me to do so). I registered with AdMob and made proper call when initializing AdMob. All is perfect. Except... there are no ADS! Not in emulator, not at any of devices. So I looked into the log and here is what I found:

"loadAd called while the ad is already loading, so aborting."

And it appears in it however I call it. How should Adview1.LoadAd be called? I call it every time application updates its status.

F1?

Thanks+greetigs 2 all!
 

pleskina

Member
Licensed User
Longtime User
This is not the cause for the lack of ads. It can take a day or two until you start seeing ads. You do not need to call LoadAd unless you want to request a new ad instead of the existing one.

Thanks, Erel. Day or two seems a long period to me, but I can wait. So, will not call LoadAd.

Regards,
D.
 

pleskina

Member
Licensed User
Longtime User
Hm, several days have passed and I still can't see any ADs... what should I suspect on now?

Regards,
D.
 

eps

Expert
Licensed User
Longtime User
Pleskina

If you log in to Admob what does your AdMob console tell you? Is the advert still inactive, has it received any impressions?

PM me for more info. Might be more productive to take this offline.

Basically you have the B4A code, with the advertiser code (do not share!) from AdMob Console, in your B4A code and are calling it in the Activity Create part.

AdView.Initialize (your AdMob 'advertiser code' goes here) and AdView.Load etc..

You've edited your manifest file, or used the manifest editor in the SDK to include the required intents for AdMob. Noting that it

You've enabled the AdMob advert in the AdMob console.

This should all work, within about 1 - 2 hours.
 
Last edited:

pleskina

Member
Licensed User
Longtime User
Thanks 4 all info and help to Philip. AdMob now seems to work. Well, at least on emulators and my Samsung GT 10.1.

On my ViewSonic V350 phone, AdMob reports failure with ErrorCode "A network error occurred". So descriptive. Is there a way to find out which network error it was since all other network-related things work properly?

Attched is the log, I replaced my slot ID with "xxxxxxxxxxx..." so don't think that is the cause of the error. :)

Thanks,
Davor
 

Attachments

  • log.zip
    18.5 KB · Views: 180

eps

Expert
Licensed User
Longtime User
Davor, what have you got in your Manifest file or in the Manifest Editor within the SDK?

Something like this (in the Editor, under Project)..

AddApplicationText(
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)
 

pleskina

Member
Licensed User
Longtime User
AddApplicationText(<!-- *** For AdMob: manually added *** -->
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)
 

eps

Expert
Licensed User
Longtime User
AddApplicationText(<!-- *** For AdMob: manually added *** -->
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)

I've got :

B4X:
              <!-- *** For AdMob: manually added *** -->
 <activity android:name="com.google.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

    </application>
</manifest>

Which looks about the same... I've included the two ending XML tags, as that's where my Admob changes reside (when the manifest is edited manually), which I'm starting to move away from.
 

schwisti

Member
Licensed User
Longtime User
Hallo,
is it possible to add Interstitial-ads with this library? Since the new AdMob version it seems, that everyone can add Interstitial-Ads.
Thank you very much!
Chris
 

hanyelmehy

Active Member
Licensed User
Longtime User
Hi,
When try your java code (setObject(new AdView(ba.activity, (AdSize)Size, PublisherId));)
i get error (setObject) not defined ,any help?
also can you please add Interstitial-ads to library
Thank you
 

Kwame Twum

Active Member
Licensed User
Longtime User
Hello everyone, I found a note on the google developer webpage which worries me quite a bit.
It read "Warning: Make sure you're in test mode during development to avoid being disabled for clicking your own ads."
Fortunately, you also mentioned in the tutorial that when using the emulator, a test ad will appear instead of a real one so I assume that issue of setting test devices is handled in the library.
With that said, I want to know when the app will start being served with real ads, is it when you compile with the Release or Release (Obfuscated) Option?
 

Douglas Farias

Expert
Licensed User
Longtime User
Erel how to use with the new admob key ?
ca-app-pub-0231280482162759/5909518441
exemple this is not my key *-*
 

GMan

Well-Known Member
Licensed User
Longtime User
The code should be inserted as "pub-xxxxxxxxxxxxxxxxxxx"
Thisis not the ca-pub...xxxxx or a part of it !

@pleskina:
in what country your are living ?
As written, here in DE there are some very very different rules before you can get registred.
 
Top