B4A Library AdManager Library

Pendrush

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

AdManager

Author:
Author: Google - B4a Wrapper: Pendrush
Version: 1.01
  • AdManager
    • Events:
      • AdClicked
      • AdClosed
      • AdFailedToLoad (Error As String)
      • AdImpression
      • AdLeftApplication
      • AdLoaded
    • Functions:
      • BringToFront
      • Initialize (EventName As String)
        Initialize Banner Ad
        AdManager1.Initialize("AdManager1")
      • Invalidate
      • Invalidate2 (arg0 As android.graphics.Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • LoadBanner (AdUnitId As String, AdSize As com.google.android.gms.ads.AdSize)
        Loads an ad.
        AdManager1.LoadBanner("/30497360/adaptive_banner_test_iu/reservation", size.Native)
      • LoadBannerWithBuilder (AdUnitId As String, AdSize As com.google.android.gms.ads.AdSize, Builder As PublisherAdRequestBuilder)
        Requests an ad configured with PublisherAdRequestBuilder.
      • LoadBannerWithTestDevice (AdUnitId As String, AdSize As com.google.android.gms.ads.AdSize, TestDevice As String)
        Requests an ad.
        TestDevice - The test device id. You can see the id in the unfiltered logs.
      • Pause
        This method should be called in the parent Activity_Pause method.
      • RemoveView
      • RequestFocus As Boolean
      • Resume
        This method should be called in the parent Activity_Resume method.
      • SendToBack
      • SetBackgroundImage (arg0 As android.graphics.Bitmap) As BitmapDrawable
      • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
      • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
      • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • Properties:
      • Background As android.graphics.drawable.Drawable
      • Color As Int [write only]
      • Enabled As Boolean
      • Height As Int
      • Left As Int
      • Padding As Int()
      • Parent As Object [read only]
      • Tag As Object
      • Top As Int
      • Visible As Boolean
      • Width As Int
  • AdManagerInterstitial
    • Events:
      • AdClicked
      • AdClosed
      • AdFailedToLoad (Error As String)
      • AdImpression
      • AdLeftApplication
      • AdLoaded
    • Functions:
      • Initialize (EventName As String, AdUnitId As String)
        Initialize Interstitial Ad.
        AdManagerInterstitial1.Initialize("AdManagerInterstitial1", "/6499/example/interstitial")
      • IsInitialized As Boolean
      • IsLoaded As Boolean
        Returns True if the Ad was successfully loaded and is ready to be shown.
      • LoadInterstitial
        Start loading the Ad on a background thread.
      • LoadInterstitialWithBuilder (Builder As PublisherAdRequestBuilder)
        Requests an ad configured with PublisherAdRequestBuilder.
      • LoadInterstitialWithTestDevice (TestDevice As String)
        Requests an ad.
        TestDevice - The test device id. You can see the id in the unfiltered logs.
      • ShowInterstitial
        Show the Interstitial Ad.
  • AdManagerRewarded
    • Events:
      • RewardedAdClosed
      • RewardedAdFailedToLoad (Error As String)
      • RewardedAdFailedToShow (ErrorCode As Int)
      • RewardedAdLoaded
      • RewardedAdOpened
      • UserEarnedReward (RewardType As String, RewardAmount As Int)
    • Functions:
      • Initialize (EventName As String, AdUnitId As String)
        Initialize Rewarded Ad.
        AdManagerRewarded1.Initialize("AdManagerRewarded1", "/6499/example/rewarded-video")
      • IsInitialized As Boolean
      • IsLoaded As Boolean
        Returns True if a Rewarded Ad is available and is ready to be shown.
      • LoadRewardedAd
        Start loading the Ad on a background thread.
      • LoadRewardedAdWithBuilder (Builder As PublisherAdRequestBuilder)
        Requests an ad configured with PublisherAdRequestBuilder.
      • LoadRewardedAdWithTestDevice (TestDevice As String)
        Requests an ad.
        TestDevice - The test device id. You can see the id in the unfiltered logs.
      • ShowRewardedAd
        Show the Rewarded Ad.
  • PublisherAdRequestBuilder
    • Functions:
      • AddTestDevice (DeviceId As String) As PublisherAdRequestBuilder
        Add a test device. You can see the device id in the unfiltered logs.
      • Initialize As PublisherAdRequestBuilder
      • IsInitialized As Boolean
      • NonPersonalizedAds As PublisherAdRequestBuilder
        Request non-personalized ads.

Add this to manifest:
B4X:
AddApplicationText(<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" />)
 

Attachments

Last edited:

tufanv

Expert
Licensed User
Dear Pendrush,

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

tufanv

Expert
Licensed 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 **



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




Add this to manifest:
B4X:
AddApplicationText(<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" />)
 

Pendrush

Well-Known Member
Licensed User
Last edited:
Top