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

scsjc

Well-Known Member
Licensed User
Longtime User
Hello,
i have a question, is possible preload library in SERVICE... before open at ACTIVITY....
(because it's slow to show, and sometimes close activity without load)
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
Can we get this library updated to support Google Play's designed for families program?

https://support.google.com/admob/answer/6223431?hl=en

Specifically, I am referring to the following:
Mixed-audience apps are apps that target both child and adult audiences and opt into the Designed for Families program. These apps will need to include code that sets "is_designed_for_families" to true and calls thetagForChildDirectedTreatment() method for ad requests served to a child audience. Upon seeing both"is_designed_for_families" and tagForChildDirectedTreatment() set to true, AdMob will return Designed for Families-compliant ads for that ad request.

Thank you!
Jack
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
With the latest revision of Google Play Services (ver 28), I get the following error on many (but not all) devices.

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_activity_resume (java line: 350)
java.lang.NoClassDefFoundError: android.support.v4.util.SimpleArrayMap
at com.google.android.gms.ads.internal.zzq.<init>(Unknown Source)
at com.google.android.gms.ads.internal.zzq.<init>(Unknown Source)
at com.google.android.gms.ads.internal.zzb.<init>(Unknown Source)
at com.google.android.gms.ads.internal.zzc.<init>(Unknown Source)
at com.google.android.gms.ads.internal.zzf.<init>(Unknown Source)
at com.google.android.gms.ads.internal.client.zze.zza(Unknown Source)
at com.google.android.gms.ads.internal.client.zzz.zzdb(Unknown Source)
at com.google.android.gms.ads.internal.client.zzz.zzda(Unknown Source)
at com.google.android.gms.ads.internal.client.zzz.zza(Unknown Source)
at com.google.android.gms.ads.BaseAdView.loadAd(Unknown Source)
at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
at anywheresoftware.b4a.admobwrapper.AdViewWrapper.LoadAd(AdViewWrapper.java:118)
at mobi.mindware.admob.main._activity_resume(main.java:350)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at mobi.mindware.admob.main.afterFirstLayout(main.java:111)
at mobi.mindware.admob.main.access$000(main.java:20)
at mobi.mindware.admob.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)

I have tried including android-support-v4.jar in the project, but it makes no difference. If I downgrade to rev 27, it works fine. Unfortunately, I need to use the latest version for advanced features. Any ideas?

Jack
 

schwisti

Member
Licensed User
Longtime User
Hello,
I've some Problems with AdMob.
That is what I did:

Manifest:
B4X:
'AdMob
AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

)
'End of AdMob

Main:
B4X:
...
#CanInstallToExternalStorage: True
    #AdditionalRes: F:\android-sdks\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

#End Region
...

B4X:
Sub Globals
...
Dim AdView1 As AdView
...
Ende Sub

B4X:
AdView1.Initialize2("Ad", "ca-app-pub-6365xxxxxxxxxxxx/xxxxxxxx29", AdView1.SIZE_SMART_BANNER)
    Activity.AddView(AdView1, 0dip, 0dip, 320dip, 50dip)' AdView1.LoadAd 'loads an ad
    AdView1.LoadAd
...
End Sub

Sub Ad_FailedToReceiveAd (ErrorCode As String)
    Log("failed to load Ad: " & ErrorCode)
End Sub
Sub Ad_ReceiveAd
    Log("received")
End Sub
Sub Ad_AdScreenDismissed
   Log("screen dismissed")
End Sub

Debugging shows:
"failed to load Ad: 0"

I've the actual google play jar in my additional folder. The actual AdMob library (2.0) as well.
Any ideas?

Thank you very much!
 

schwisti

Member
Licensed User
Longtime User
Thank you for your fast answer...
I created a new Ad in AdMob with a new code....same error 0
Is it OK, that I use "F:\android-sdks\platforms\android-23\android.jar", because if I use android-19, there'll come an error.
I test the app on a Samsung Galaxy S4 mini with Android 4.4.2
 

schwisti

Member
Licensed User
Longtime User
Ok'll wait...

I found this in the Log:
There was a problem getting an ad response. ErrorCode: 0
Failed to load ad: 0
There was a problem getting an ad response. ErrorCode: 0
failed to load Ad: 0
LightSensor readEvents x = 0.000000, raw = 0
failed to load Ad: 0
Starting ad request.
Use AdRequest.Builder.addTestDevice("3D4E4595F7A2D62BCCAD5077958ADF26") to get test ads on this device.
Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
Starting ad request.
Use AdRequest.Builder.addTestDevice("3D4E4595F7A2D62BCCAD5077958ADF26") to get test ads on this device.
Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
Failed to load ad: 0
failed to load Ad: 0
failed to load Ad: 0


Lade Ad1
Lade Ad1
Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.zze.zzi
VFY: unable to resolve virtual method 386: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
VFY: replacing opcode 0x6e at 0x000d
Could not find method android.security.NetworkSecurityPolicy.getInstance, referenced from method com.google.android.gms.ads.internal.t.e.a
VFY: unable to resolve static method 1032: Landroid/security/NetworkSecurityPolicy;.getInstance ()Landroid/security/NetworkSecurityPolicy;
VFY: replacing opcode 0x71 at 0x004e
Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.nb.a
VFY: unable to resolve virtual method 424: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;


Starting ad request.
Use AdRequest.Builder.addTestDevice("3D4E4595F7A2D62BCCAD5077958ADF26") to get test ads on this device.
Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.

Is there something missing? method com.google.android.gms.common.zze.zzi??

Thank you!!
 

schwisti

Member
Licensed User
Longtime User
I found it.......
In the file "host" are IPs, that goes to Doubleclick, above a comment "this file is from Adaway", but I don't installed this app. So I downloaded it and clicked on "disable add blocking"... now it works on my "old" version of my app. When I'll arrive at home, I'll check it with the new one as well.... Thank you very much for your help!!
 

sorex

Expert
Licensed User
Longtime User
Does this library support these interstitial ads or do I need some additional lib/jar?

When I add an adview and enter my interstitial "key" nothing appears.

my admob library in B4A is 2.00 and path is set to API14.

a regular banner displays fine tho.
 

Douglas Farias

Expert
Licensed User
Longtime User

sorex

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.
 
Top