B4A Library FirebaseAdmobPlus

FirebaseAdmobPlus is no longer supported, please check out GoogleMobileAds lib
https://www.b4x.com/android/forum/threads/googlemobileadssdk.128787/


Hi
This is a full wrapper over goolgle ads sdk.
https://developers.google.com/admob/android/quick-start

It supports :
- Banner (Also Adaptive Banner) | https://developers.google.com/admob/android/banner
- Interstitial | https://developers.google.com/admob/android/interstitial
- Rewerded | https://developers.google.com/admob/android/rewarded-ads
- AppOpenAds | https://developers.google.com/admob/android/app-open-ads
- UnifiedNative | https://developers.google.com/android/reference/com/google/android/gms/ads/formats/UnifiedNativeAd

First you need to follow the Firebase integration tutorial: https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
Make sure to include the Ads manifest snippet.

Note:
- This library is compatible with Admob version 19.6 or higher, So if you see any errors, please update your SDK first.
1609934035079.png


- This library will be updated as soon as Google launches the new Google Mobile Ads SDK for Android version 20.0.0 In early 2021. So several APIs currently available will be changed or retired. See this https://developers.google.com/admob/android/migration

- You should initialialize MobileSdk at first once and wait for MobileAds_onInitializationComplete
then you can add your ads.
like this:
B4X:
    Dim MobileAds As MobileAds
        MobileAds.Initialize
    Wait For MobileAds_onInitializationComplete
        ' Here You Can Load Your Ads

- For video ads to show successfully in your banner ad views, hardware acceleration must be enabled.(Add to manifest)
B4X:
SetApplicationAttribute(android:hardwareAccelerated, "true")

- By default, the Google Mobile Ads SDK initializes app measurement and begins sending user-level event data to Google immediately when the app starts.
This initialization behavior ensures you can enable AdMob user metrics without making additional code changes.
However, if your app requires user consent before these events can be sent, you can delay app measurement until you explicitly initialize the Mobile Ads SDK or load an ad.
To delay app measurement, add the following <meta-data> tag in your Manifest.
Delay app measurement until MobileAds.initialize() is called.
B4X:
AddApplicationText(
    <meta-data
        android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
        android:value="true"/>
)
 

Attachments

  • FirebaseAdmobPlus.jar
    57.7 KB · Views: 491
  • FirebaseAdmobPlus.xml
    73.1 KB · Views: 437
  • Example.zip
    15.1 KB · Views: 486
Last edited:

ArminKh1993

Active Member
HI ArminKh1993 ?
Thank you for a good library?

There is a small bug in the "IsLoaded" control time
Returns the value "null" but the default should be "false"

Please test the following codes

B4X:
 InterstitialAd.Initialize("InterstitialAd")

    Log(InterstitialAd.IsLoaded)

    If InterstitialAd.IsLoaded = True Then

        Log("InterstitialAd  Is Loaded and go to show ad")

    Else

        InterstitialAd.LoadAdWithBuilder(xxx,builder)

    End If


B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.google.android.gms.ads.InterstitialAd.isLoaded()' on a null object reference
I checked and this is being returned by Google SDK itself.
In any case, if the onAdLoaded event raised, it means that the ad is loaded and you do not need to check again.
But, I will try to resolve this issue manually with the new Google update that will be released soon.
 

SMOOTSARA

Active Member
Licensed User
Longtime User
Hi ArminKh1993 ?

I installed your sample
But I have the following error in the "AppOpenAds" section


B4X:
** Activity (main) Pause, UserClosed = false **
** Activity (actappopenads) Create, isFirst = true **
** Activity (actappopenads) Resume **
AppOpenAds_onAppOpenAdLoaded
java.lang.NoSuchMethodError: No virtual method show(Landroid/app/Activity;Lcom/google/android/gms/ads/FullScreenContentCallback;)V in class Lcom/google/android/gms/ads/appopen/AppOpenAd; or its super classes (declaration of 'com.google.android.gms.ads.appopen.AppOpenAd' appears in /data/app/b4a.remote.config-1/base.apk)
    at com.b4a.admobwrapper.AppOpenAdsWrapper.Show(AppOpenAdsWrapper.java:117)
    at b4a.remote.config.actappopenads._appopenads_onappopenadloaded(actappopenads.java:474)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6138)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
** Activity (actappopenads) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**

And i update

2. Android SDK + Required Resources

in
https://www.b4x.com/b4a.html

1613331170433.png


1613331203960.png
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
Hi ArminKh1993 ?

I installed your sample
But I have the following error in the "AppOpenAds" section


B4X:
** Activity (main) Pause, UserClosed = false **
** Activity (actappopenads) Create, isFirst = true **
** Activity (actappopenads) Resume **
AppOpenAds_onAppOpenAdLoaded
java.lang.NoSuchMethodError: No virtual method show(Landroid/app/Activity;Lcom/google/android/gms/ads/FullScreenContentCallback;)V in class Lcom/google/android/gms/ads/appopen/AppOpenAd; or its super classes (declaration of 'com.google.android.gms.ads.appopen.AppOpenAd' appears in /data/app/b4a.remote.config-1/base.apk)
    at com.b4a.admobwrapper.AppOpenAdsWrapper.Show(AppOpenAdsWrapper.java:117)
    at b4a.remote.config.actappopenads._appopenads_onappopenadloaded(actappopenads.java:474)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6138)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
** Activity (actappopenads) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**

And i update

2. Android SDK + Required Resources

in
https://www.b4x.com/b4a.html

View attachment 108003

View attachment 108004

Check post number 11. https://www.b4x.com/android/forum/threads/firebaseadmobplus.126078/post-789111

You need to update the admob sdk to 19.6.0 through the sdkmanager
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
You need to download everything new.
Sdk manager at instructions 2
 

asales

Expert
Licensed User
Longtime User
This library will be updated as soon as Google launches the new Google Mobile Ads SDK for Android version 20.0.0 In early 2021. So several APIs currently available will be changed or retired. See this https://developers.google.com/admob/android/migration
When you updated this lib, please, rename the Adview (banner) component to AdviewPlus or other name.
I use the Adview banner from the original Admob lib from Erel and I get a conflict with this lib when I try to use the AppOpenAd.
Thanks.
 

ArminKh1993

Active Member
When you updated this lib, please, rename the Adview (banner) component to AdviewPlus or other name.
I use the Adview banner from the original Admob lib from Erel and I get a conflict with this lib when I try to use the AppOpenAd.
Thanks.
Open xml file of library and rename ìt by yourself
 
Top