Unity Ads Android SDK API reference
Access the Unity Ads SDK public API reference to view available classes, methods, and properties you can use in Java to integrate and control ad behavior in your Android app.
Read time 6 minutesLast updated 4 hours ago
This article contains the following API documentation: Classes Enums
PlacementState
FinishState
UnityAdsInitializationError
UnityAdsLoadError
UnityAdsShowError
UnityAdsShowCompletionState
UnityAdsError
Classes
UnityAds
Use this namespace to implement interstitial ad content, such as rewarded or non-rewarded video, or banner ads.initialize
Initializes the ads service, with a specified Game ID, test mode status, and initialization listener.initialize(final Context context, final String gameId, final boolean testMode, final IUnityAdsInitializationListener initializationListener)
Parameter | Description |
---|---|
| The current Android
|
| The platform-specific Unity game identifier for your project, found on the Unity Ads Monetization dashboard. |
| Use Test mode to test your integration without serving live ads. Use
|
| Optionally enables the SDK with
|
load
Loads ad content for a specified ad unit. You must callpublic static void load(final String adUnitId, final UnityAdsLoadOptions loadOptions, final IUnityAdsLoadListener listener)
load
show
Parameter | Description |
---|---|
| The identifier for the ad unit you want to load with ad content. |
| A collection of options that modify ad behavior. |
| Optionally loads ad content with
|
show
Displays loaded ad content in a specified ad unit.public static void show(final Activity activity, final String adUnitId, final UnityAdsShowOptions options, final IUnityAdsShowListener showListener)
Parameter | Description |
---|---|
| The current Android
|
| The identifier for the ad unit you want to show. |
| A collection of options modifying ad behavior. |
| Optionally shows content with
|
addListener
Adds a listener that will receive Unity Ads callbacks. In versions 3.1.0 and later, you can register multiple listeners. This is especially helpful for mediation customers.public static void addListener(IUnityAdsListener listener)
Parameter | Description |
---|---|
| A listener for Unity Ads callbacks. |
removeListener
Removes an active [public static void removeListener(IUnityAdsListener listener)
IUnityAdsListener
Parameter | Description |
---|---|
| A listener for Unity Ads callbacks. |
getVersion
Returns the current Ads SDK version.public static String getVersion()
getPlacementState
Returns the state of a specified ad unit.public static PlacementState getPlacementState(String adUnitId)
Parameter | Description |
---|---|
| The identifier for the ad unit you want to query. |
setDebugMode
Controls the amount of logging output from the SDK. Set topublic static void setDebugMode(boolean debugMode)
true
getDebugMode
Returnspublic static boolean getDebugMode()
true
isInitialized
Returnspublic static boolean isInitialized()
true
false
isSupported
Returnspublic static bool isSupported()
true
false
UnityAdsLoadOptions
This class contains optional metadata to include with thepublic class UnityAdsLoadOptions extends UnityAdsBaseOptions
load
setAdMarkup
This method takes the ad markup returned from the bidder service. When a bidder from Unity's ad network wins a header bidding auction, the Unity Ads SDK receives ad markup from the mediated exchange. The ad markup string contains information needed for Unity to load and show the ad.public void setAdMarkup(String adMarkup)
setObjectId
This method sets the loaded ad object ID as the ad object ID to show.public void setObjectId(String objectId)
BannerView
public BannerView(Activity activity, String adUnitId, UnityBannerSize size)
Parameter | Description |
---|---|
| The current Android
|
| The identifier for the ad unit you want to show. |
| The
|
getPlacementId
Returns the ad unit ID for the Banner ad unit.public String getPlacementId()
getSize
Thepublic UnityBannerSize getSize()
size
setListener
Sets the active listener for the banner.public void setListener(IListener listener)
getListener
Retrieves the active listener for the banner.public IListener getListener()
load
The basic method for requesting an ad for the banner.public void load()
destroy
Call this method to remove the banner from the view hierarchy when you're no longer using it.public void destroy()
UnityBannerSize
Use this class to define the height and width of a banner object.public UnityBannerSize(int width, int height)
getWidth
Returns the width in pixels of the banner object.public int getWidth()
getHeight
Returns the height in pixels of the banner object.public int getHeight()
Enums
PlacementState
The enumerated states of an ad unit.Value | Description |
---|---|
| The ad unit is ready to show ads. |
| The ad unit is not available. |
| The ad unit has been disabled. |
| The ad unit is waiting to be ready. |
| The ad unit has no advertisements to show. |
FinishState
The enumerated states of the user's interaction with the ad. The SDK passes this value to theonUnityAdsDidFinish
Value | Description |
---|---|
| Indicates that the ad failed to complete due to a Unity service error. |
| Indicates that the user skipped the ad. |
| Indicates that the user successfully finished watching the ad. |
UnityAdsInitializationError
The enumerated reasons for SDK initialization to fail.Value | Description |
---|---|
| An error occurred due to the environment or internal services. |
| An error occurred due to invalid arguments in the
|
| An error occurred due to a URL being blocked. |
UnityAdsShowCompletionState
The enumerated causes for the ad to have finished.Value | Description |
---|---|
| Indicates that the user skipped the ad. |
| Indicates that the ad played in its entirety. This typically indicates that the user can be rewarded for watching the full ad. |
UnityAdsLoadError
The enumerated reasons for an ad unit failing to load.Value | Description |
---|---|
| The ad failed to load due to the SDK not being initialized. |
| The ad failed to load due to an internal Unity Ads service error. |
| The ad failed to load due to invalid arguments in the
|
| The ad failed to load because no content was available from the network. |
| The ad failed to load within the specified timeframe. |
UnityAdsShowError
The enumerated reasons for an ad unit failing to show.Value | Description |
---|---|
| The ad failed to show due to the SDK not being initialized. |
| The ad failed to show because the ad unit was not ready. |
| The ad failed to show because of a media player error. |
| The ad failed to show due to invalid arguments in the
|
| The ad failed to show because of an internet connection error. |
| The ad failed to show because an ad was already showing. |
| The ad failed to show due to an internal Unity Ads service error. |
UnityAdsError
The enumerated reasons for an add to fail....
Interfaces
IUnityAdsInitializationListener
Implement this interface to handlevoid onInitializationComplete(); void onInitializationFailed(UnityAds.UnityAdsInitializationError error, String message);
initialize
onInitializationComplete
This callback method handles logic for the SDK successfully initializing.onInitializationFailed
This callback method handles logic for the SDK failing to initialize.Parameter | Description |
---|---|
| The
|
| A message associated with the error. |
IUnityAdsLoadListener
Implement this interface to handlevoid onUnityAdsAdLoaded(String placementId); void onUnityAdsFailedToLoad(String placementId, UnityAds.UnityAdsLoadError error, String message);
load
onUnityAdsAdLoaded
This callback method handles logic for the ad unit successfully loading.Parameter | Description |
---|---|
| The identifier for the ad unit that loaded content. |
onUnityAdsFailedToLoad
This callback method handles logic for the ad unit failing to load.Parameter | Description |
---|---|
| The identifier for the ad unit that failed to load content. |
| The
|
| A message associated with the error. |
IUnityAdsShowListener
Implement this interface to handlevoid onUnityAdsShowFailure(String placementId, UnityAds.UnityAdsShowError error, String message); void onUnityAdsShowStart(String placementId); void onUnityAdsShowClick(String placementId); UnityAds.UnityAdsShowCompletionState state;
show
onUnityAdsShowFailure
This callback method handles logic for the ad unit failing to show.Parameter | Description |
---|---|
| The identifier for the ad unit that failed to show content. |
| The
|
| A message associated with the error. |
onUnityAdsShowStart
This callback method handles logic for the ad starting to play.Parameter | Description |
---|---|
| The identifier for the ad unit showing the content. |
onUnityAdsShowClick
This callback method handles logic for the user clicking on the ad.Parameter | Description |
---|---|
| The identifier for the ad unit showing the content. |
onUnityAdsShowComplete
This callback method handles logic for the ad finishing.Parameter | Description |
---|---|
| The identifier for the ad unit showing the content. |
Indicates whether the ad was skipped or completed. |
onUnityAdsReady
Specify logic for ad content being ready to display through a specified ad unit.
Parameter | Description |
---|---|
| The identifier for the ad unit that is ready. |
onUnityAdsDidError
Specify logic for ad content failing to display due to an error.
Parameter | Description |
---|---|
The error that caused the ad to fail. | |
| A message associated with the error. |
onUnityAdsDidStart
Specify logic for the player triggering an ad to show.
Parameter | Description |
---|---|
| The identifier for the ad unit that is showing the ad. |
OnUnityAdsDidFinish
Specify logic for the player watching the ad in its entirety.
Parameter | Description |
---|---|
| The identifier for the ad unit that finished showing. |
| The resulting user event of the ad showing. |
IListener
String mObjectId = UUID.randomUUID().toString(); void onBannerLoaded(BannerView bannerAdView); void onBannerShown(BannerView bannerAdView); void onBannerClick(BannerView bannerAdView); void onBannerFailedToLoad(BannerView bannerAdView, BannerErrorInfo errorInfo); void onBannerLeftApplication(BannerView bannerView);
onBannerLoaded
This callback fires when the banner finishes loading an ad. The view parameter references the banner that should be inserted into the view hierarchy.Parameter | Description |
---|---|
| The banner object that loaded. |
onBannerClick
This callback fires when the banner is clicked.Parameter | Description |
---|---|
| The banner object that loaded. |
onBannerError
This callback fires when an error occurs showing the banner.Parameter | Description |
---|---|
| The banner object that loaded. |
| A class containing information about the banner load error. |
onBannerLeftApplication
This callback fires when the banner links outside the application.Parameter | Description |
---|---|
| The banner object that loaded. |