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:
I got that email too. Waiting for Erel's answer :D
 
It is working correctly now. But I can't seem to get the new ad units sizes (728x90, 300x250, 468x60). Whichever size I set to, it still shows the old ad size.

Wonder if this is the issue of AdMob itself, or the wrapper.
 
Anyone who knows which log-messages to look out for to determine if the app is sending requests and is receiving ads or even better, if the app is not receiving any ads due to a modified hosts-file or an ad-blocker?

I'd like to implement a verification to see if an ad-blocker (or a modified host-file) is present on the phone. If yes, I will put my own "ad-image" (in the space meant for the ad) with a link to my site.
 
Hi,

This is one way to do this.

Use 2 panels. First show a panel with your own "ad" on it, say an image or some text. Click event on this panel brings you to wherever you want to.

adview has 2 possible subs, ReceivedAd and FailedToReceiveAd. In received ad, i'll show a 2nd panel which has the adview on it and make my own panel not visible.

In FailedToReceivedAd, you can hide the ad panel and make your own one visible again.

Hope that helps... or am I getting your question wrong?

Cheers!
 
@ssg

Spot on my friend! :icon_clap:

To see if an ad-blocker is present, I will adapt this code to B4A:

Code: Copy
try {
    if (InetAddress.getByName("a.admob.com").getHostAddress().equals("127.0.0.1") ||
        InetAddress.getByName("mm.admob.com").getHostAddress().equals("127.0.0.1") ||
        InetAddress.getByName("p.admob.com").getHostAddress().equals("127.0.0.1") ||
        InetAddress.getByName("r.admob.com").getHostAddress().equals("127.0.0.1")) {
        //Naughty Boy - Punishing code goes here.
        // In my case its a dialog which goes to the pay-for version 
        // of my application in the market once the dialog is closed.
    }
} catch (UnknownHostException e) { } //no internet
 
Is it possible to detect if a user has clicked on an ad?

I'm thinking about a mechanism to disable the ads for some time if a user has clicked on one.
 
Is it possible to detect if a user has clicked on an ad?

I'm thinking about a mechanism to disable the ads for some time if a user has clicked on one.
this is a very good idea, but I think this is not possible. If anyone of the gurus can tell us something...
 
Hmm, should be possible if the wrapper will wrap these events, too:

public void onPresentScreen(Ad ad);
public void onDismissScreen(Ad ad);
public void onLeaveApplication(Ad ad);
 
How do you set those sizes when you setup the AdMob panel?

Code: Copy
Activity.AddView(AdBox, 0dip, 375dip, 320dip, 50dip)

The code above is just for a "phone" size, but now with the new variables, how's done?
 
Back
Top