B4A Library Unity Ads Library

Original library: https://github.com/Unity-Technologies/unity-ads-android
Based on Unity Ads Library v4.13.0 (14 Jan 2025).
Banner, Interstitial and Rewarded Video.


UnityAds

Author:
Author: Unity - B4a Wrapper: Pendrush
Version: 4.85
  • UnityAdsBanner
    • Events:
      • OnBannerClick
      • OnBannerFailedToLoad (Error As String)
      • OnBannerLeftApplication
      • OnBannerLoaded
      • OnBannerShown
      • OnInitializationComplete
      • OnInitializationFailed (Error As String)
    • Functions:
      • BringToFront
      • Initialize (arg1 As String)
      • InitializeBanner (EventName As String, GameID As String, TestMode As Boolean, PlacementID As String)
        EventName - Event name
        GameID - The Unity Game ID for your Project, located in the developer dashboard.
        TestMode - When set to true, only test ads display.
        PlacementID - The Placement ID, located on the developer dashboard.
        UnityAdsBanner.InitializeBanner("BannerAd", "3054608", True, "banner")
        Activity.AddView(UnityAdsBanner, 100%x/2-160dip, 0, 320dip, 50dip)
        UnityAdsBanner.LoadBanner
      • Invalidate
      • Invalidate2 (arg0 As android.graphics.Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • LoadBanner
        Load banner Ad.
      • onInitializationComplete
      • onInitializationFailed (error As com.unity3d.ads.UnityAds.UnityAdsInitializationError, message As String)
      • RemoveView
      • RequestFocus As Boolean
      • 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
  • UnityAdsInterstitial
    • Events:
      • OnUnityAdsAdLoaded (PlacementID As String)
      • OnUnityAdsFailedToLoad (Error As String)
      • OnUnityAdsShowClick (PlacementID As String)
      • OnUnityAdsShowComplete (PlacementID As String, State As String)
      • OnUnityAdsShowFailure (Error As String)
      • OnUnityAdsShowStart (PlacementID As String)
    • Functions:
      • InitializeInterstitial (EventName As String, GameID As String, TestMode As Boolean, PlacementID As String)
        EventName - Event name
        GameID - The Unity Game ID for your Project, located in the developer dashboard.
        TestMode - When set to true, only test ads display.
        PlacementID - The Placement ID, located on the developer dashboard.
        UnityAdsInterstitial.InitializeInterstitial("InterstitialAds", "14851", True, "rewardedVideo")
      • IsInitialized As Boolean
      • LoadAd
        Load Interstitial/Rewarded Ad.
      • ShowAd
        Show Ad


For InterstitialAd and for RewardedVideoAd you need to add this in your manifest:
B4X:
AddApplicationText(<activity
            android:name="com.unity3d.services.ads.adunit.AdUnitActivity"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
            android:exported="false"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
        <activity
            android:name="com.unity3d.services.ads.adunit.AdUnitTransparentActivity"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
            android:exported="false"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
        <activity
            android:name="com.unity3d.services.ads.adunit.AdUnitTransparentSoftwareActivity"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
            android:exported="false"
            android:hardwareAccelerated="false"
            android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
        <activity
            android:name="com.unity3d.services.ads.adunit.AdUnitSoftwareActivity"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
            android:exported="false"
            android:hardwareAccelerated="false"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
        <activity
            android:name="com.unity3d.ads.adplayer.FullScreenWebViewDisplay"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
            android:exported="false"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
        <provider
            android:name="androidx.startup.InitializationProvider"
            android:authorities="${applicationId}.androidx-startup" >
            <meta-data
                android:name="androidx.lifecycle.ProcessLifecycleInitializer"
                android:value="androidx.startup" />
            <meta-data
                android:name="com.unity3d.services.core.configuration.AdsSdkInitializer"
                android:value="androidx.startup" />
        </provider>)

Download library from:
 

Attachments

  • UnityAdsExample.zip
    5.2 KB · Views: 36
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Yes i know, @Pendrush
I did liked even if i do not like Ads ;-)
 

Douglas Farias

Expert
Licensed User
Longtime User
Hi @Pendrush
First, Thank you for the lib, i m testing here.

one report...
the UnityAdsInterstitial.IsInitialized is always returning false.
the IsReady is true but the IsInitialized is false.

i have not tested banner, but i think it is with same problem.

thx
 

Douglas Farias

Expert
Licensed User
Longtime User
Hello @Pendrush
can you please update this lib to lasted version of unity sdk (3.7.5)? or upload the source code? thank you ???
 

Blueforcer

Well-Known Member
Licensed User
Longtime User
Is this still working?
B4X:
UnityAdsInterstitial.InitializeInterstitial("InterstitialAds", "4782531", False, "Interstitial_Android")
i always get
OnUnityAdsFailedToLoad: Error: INVALID_ARGUMENT, Error message: No placement configured for id: Interstitial_Android, PlacementId: Interstitial_Android

as placement ID i entered the ad-unit ID, since i dont find any PlacementId

1654252331268.png


is this correct?
 

Pendrush

Well-Known Member
Licensed User
Longtime User
Top