Skip to content

sdk_android_api_reference

Janne Nikula edited this page Jun 10, 2016 · 4 revisions

Unity Ads SDK 2.0 - Android API Reference

This is the public Android API for Unity Ads SDK 2.0.

Contents


UnityAds Class

Enumerations

The following enumerations are available as part of the UnityAds class.

⇧ Back to top

Static Methods

UnityAds.getDebugMode

public static boolean getDebugMode();

Returns true if Debug Mode is enabled.

⇧ Back to top

UnityAds.getListener

public static IUnityAdsListener getListener();

Returns the current assigned Unity Ads listener.

See IUnityAdsListener.

⇧ Back to top

UnityAds.getPlacementState

public static PlacementState getPlacementState();
public static PlacementState getPlacementState(String placementId);

Returns the state of the specified ad placement ID. If a placement is not specified, the default ad placement will be used instead.

Parameter Description
placementId The ad placement identifier. This can be found listed under the iOS platform of your project in the Unity Ads dashboard.

See UnityAds.PlacementState.

⇧ Back to top

UnityAds.getVersion

public static String getVersion();

Returns the Unity Ads SDK version as a string.

⇧ Back to top

UnityAds.initialize

public static void initialize(final Activity activity, final String gameId, final IUnityAdsListener listener );
public static void initialize(final Activity activity, final String gameId, final IUnityAdsListener listener, final boolean testMode);

Initializes the Unity Ads SDK using the specified game ID.

Parameter Description
activity The current Android activity used to call this method.
gameId The platform specific game identifier. This can be found listed under your project in the Unity Ads dashboard.
listener The listener class that implements IUnityAdsListener.
testMode Enables Test Mode when set to true. Test Mode defaults to being disabled when a value is not specified. While Test Mode is enabled, only test ads will be shown. Test ads do not generate any stats or revenue.

⇧ Back to top

UnityAds.isInitialized

public static boolean isInitialized();

Returns true if the Unity Ads SDK is initialized.

⇧ Back to top

UnityAds.isReady

public static boolean isReady();
public static boolean isReady(String placementId);

Returns true if the specified ad placement is ready to show an ad campaign. If a placement is not specified, the default ad placement will be used instead.

Parameter Description
placementId The ad placement identifier. This can be found listed under the Android platform of your project in the Unity Ads dashboard.

⇧ Back to top

UnityAds.isSupported

public static boolean isSupported();

Returns true if Unity Ads is supported by the current device. Call this method before attempting to initialize Unity Ads.

⇧ Back to top

UnityAds.setDebugMode

public static void setDebugMode(boolean debugMode);

Parameter Description
debugMode Logs are verbose when set to true, and minimal when false.

⇧ Back to top

UnityAds.setListener

public static void setListener(IUnityAdsListener listener);

Parameter Description
listener The listener class that implements IUnityAdsListener.

⇧ Back to top

UnityAds.show

public static void show(final Activity activity);
public static void show(final Activity activity, final String placementId);

Shows an ad campaign using the specified ad placement. If no placement is specified, the default placement is used instead.

After the ad is shown, the method IUnityAdsListener.onUnityAdsFinish will be called when the ad placement is closed. This callback method can be used to reward players for opting-in to watch video ads.

Parameter Description
activity The current Android activity used to call this method.
placementId The ad placement identifier. This can be found listed under the Android platform of your project in the Unity Ads dashboard.

⇧ Back to top


IUnityAdsListener Interface

Callback Methods

IUnityAdsListener.onUnityAdsError

void onUnityAdsError(UnityAds.UnityAdsError error, String message);

In addition to error logs, this method is called when an error occurs with Unity Ads. This method can be used to assist in debugging efforts, as well as for collect statistics on various failure scenarios.

Parameter Description
error The Unity Ads error that occurred. See UnityAds.UnityAdsError.
message A description of the error that occurred.

⇧ Back to top

IUnityAdsListener.onUnityAdsFinish

void onUnityAdsFinish(String placementId, UnityAds.FinishState result);

This method is called after the ad placement is closed. For each call to UnityAds.show, there will be a call to IUnityAdsListener.onUnityAdsFinish, including all failure scenarios.

Parameter Description
placementId The ad placement identifier. This can be found listed under the Android platform of your project in the Unity Ads dashboard.
result The state in which the ad was finished. See UnityAds.FinishState.

⇧ Back to top

IUnityAdsListener.onUnityAdsReady

void onUnityAdsReady(String placementId);

This method is called when the specified ad placement becomes ready to show an ad campaign.

Parameter Description
placementId The ad placement identifier. This can be found listed under the Android platform of your project in the Unity Ads dashboard.

⇧ Back to top

IUnityAdsListener.onUnityAdsStart

void onUnityAdsStart(String placementId);

This method is called at the start of video playback for the ad campaign being shown.

Parameter Description
placementId The ad placement identifier. This can be found listed under the Android platform of your project in the Unity Ads dashboard.

Note: If a video fails to start after the call to UnityAds.show, this method may not be called. In this case, Unity Ads will skip ahead to call IUnityAdsListener.onUnityAdsFinish with a result of UnityAds.FinishState.ERROR.

⇧ Back to top

You can’t perform that action at this time.