B4A Library AdManager Library

Wrapper for AdManager Library: https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start
Banner, Interstitial and Rewarded Ads only.



Add this in manifest (replace ca-app-pub-3940256099942544~3347511713 with your APP ID):
B4X:
AddApplicationText(
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>

<meta-data
            android:name="com.google.android.gms.ads.AD_MANAGER_APP"
            android:value="true"/> 
            <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> 
         
            <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
          android:theme="@android:style/Theme.Translucent.NoTitleBar"
          android:exported="false"/>
            <meta-data
          android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version" />
        <receiver
                    android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
                    android:enabled="true"
                    android:exported="false" >
                </receiver>
     
          <service
                    android:name="com.google.android.gms.measurement.AppMeasurementService"
                    android:enabled="true"
                    android:exported="false" />
                 
         <receiver
                    android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
                    android:enabled="true"
                    android:exported="true"
                    android:permission="android.permission.INSTALL_PACKAGES" >
                    <intent-filter>
                        <action android:name="com.android.vending.INSTALL_REFERRER" />
                    </intent-filter>
        </receiver>
        <service
                    android:name="com.google.android.gms.measurement.AppMeasurementJobService"
                    android:enabled="true"
                    android:exported="false"
                    android:permission="android.permission.BIND_JOB_SERVICE" />)


v1.52 new banner sizes for static banners:
  • ADSIZE_BANNER - Mobile Marketing Association (MMA) banner ad size (320x50 density-independent pixels).
  • ADSIZE_FULL_BANNER - Interactive Advertising Bureau (IAB) full banner ad size (468x60 density-independent pixels).
  • ADSIZE_LARGE_BANNER - Large banner ad size (320x100 density-independent pixels).
  • ADSIZE_LEADERBOARD - Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels).
  • ADSIZE_MEDIUM_RECTANGLE - Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels).
 

Attachments

  • AdManagerLibrary.zip
    15.2 KB · Views: 307
  • AdManagerExample.zip
    14.7 KB · Views: 311
Last edited:

tufanv

Expert
Licensed User
Longtime User
Dear Pendrush,

Thanks very much for your support and quick help. Will try this out asap
 

tufanv

Expert
Licensed User
Longtime User
Dear Pendrush,

Rewarded and interstitial works perfect on emulator, but when I click on banner ad I get an error: Maybe because of Emulator ?

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (actinterstitial) Create, isFirst = true **
** Activity (actinterstitial) Resume **
AdLoaded - event fire
** Activity (actinterstitial) Pause, UserClosed = false **
sending message to waiting queue (admanagerinterstitial1_adclosed)
running waiting messages (1)
AdClosed - event fire
** Activity (actinterstitial) Resume **
** Activity (actinterstitial) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (actrewarded) Create, isFirst = true **
** Activity (actrewarded) Resume **
RewardedAdLoaded - event fire
** Activity (actrewarded) Pause, UserClosed = false **
sending message to waiting queue (admanagerrewarded1_rewardedadopened)
sending message to waiting queue (admanagerrewarded1_rewardedadclosed)
running waiting messages (2)
RewardedAdOpened - event fire
RewardedAdClosed - event fire
** Activity (actrewarded) Resume **
** Activity (actrewarded) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (actbanner) Create, isFirst = true **
Error occurred on line: 66 (actBanner)
java.lang.RuntimeException: Method: getCurrentOrientationAnchoredAdaptiveBannerAdSize not found in: com.google.android.gms.ads.AdSize
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:366)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
    at b4a.example.actbanner._getadaptiveadsize(actbanner.java:407)
    at b4a.example.actbanner._activity_create(actbanner.java:368)
    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 b4a.example.actbanner.afterFirstLayout(actbanner.java:105)
    at b4a.example.actbanner.access$000(actbanner.java:17)
    at b4a.example.actbanner$WaitForLayout.run(actbanner.java:83)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6680)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
** Activity (actbanner) Resume **




 

Pendrush

Well-Known Member
Licensed User
Longtime User
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…