using System;
using System.Collections.Generic;
using UnityEngine;
using AppLovinMax.ThirdParty.MiniJson;
///
/// Android AppLovin MAX Unity Plugin implementation
///
public class MaxSdkAndroid : MaxSdkBase
{
private static readonly AndroidJavaClass MaxUnityPluginClass =
new AndroidJavaClass("com.applovin.mediation.unity.MaxUnityPlugin");
private static BackgroundCallbackProxy BackgroundCallback = new BackgroundCallbackProxy();
public static MaxUserServiceAndroid UserService
{
get { return MaxUserServiceAndroid.Instance; }
}
static MaxSdkAndroid()
{
InitializeEventExecutor();
}
#region Initialization
///
/// Set AppLovin SDK Key.
///
/// This method must be called before any other SDK operation
///
/// AppLovin SDK Key. Must not be null.
public static void SetSdkKey(string sdkKey)
{
MaxUnityPluginClass.CallStatic("setSdkKey", sdkKey);
}
///
/// Initialize the default instance of AppLovin SDK.
///
/// Please make sure that application's Android manifest or Info.plist includes the AppLovin SDK key.
///
/// OPTIONAL: Set the MAX ad unit ids to be used for this instance of the SDK. 3rd-party SDKs will be initialized with the credentials configured for these ad unit ids.
/// This should only be used if you have different sets of ad unit ids / credentials for the same package name.
///
public static void InitializeSdk(string[] adUnitIds = null)
{
var serializedAdUnitIds = (adUnitIds != null) ? string.Join(",", adUnitIds) : "";
MaxUnityPluginClass.CallStatic("initializeSdk", serializedAdUnitIds, GenerateMetaData(), BackgroundCallback);
}
///
/// Check if the SDK has been initialized
///
/// True if SDK has been initialized
public static bool IsInitialized()
{
return MaxUnityPluginClass.CallStatic("isInitialized");
}
#endregion
#region User Info
///
/// Set an identifier for the current user. This identifier will be tied to SDK events and our optional S2S postbacks.
///
/// If you're using reward validation, you can optionally set an identifier to be included with currency validation postbacks.
/// For example, a username or email. We'll include this in the postback when we ping your currency endpoint from our server.
///
///
/// The user identifier to be set. Must not be null.
public static void SetUserId(string userId)
{
MaxUnityPluginClass.CallStatic("setUserId", userId);
}
///
/// User segments allow us to serve ads using custom-defined rules based on which segment the user is in. For now, we only support a custom string 32 alphanumeric characters or less as the user segment.
///
public static MaxUserSegment UserSegment
{
get { return SharedUserSegment; }
}
///
/// This class allows you to provide user or app data that will improve how we target ads.
///
public static MaxTargetingData TargetingData
{
get { return SharedTargetingData; }
}
#endregion
#region MAX
///
/// Returns the list of available mediation networks.
///
/// Please call this method after the SDK has initialized.
///
public static List GetAvailableMediatedNetworks()
{
var serializedNetworks = MaxUnityPluginClass.CallStatic("getAvailableMediatedNetworks");
return MaxSdkUtils.PropsStringsToList(serializedNetworks);
}
///
/// Present the mediation debugger UI.
/// This debugger tool provides the status of your integration for each third-party ad network.
///
/// Please call this method after the SDK has initialized.
///
public static void ShowMediationDebugger()
{
MaxUnityPluginClass.CallStatic("showMediationDebugger");
}
///
/// Present the creative debugger UI.
/// This debugger tool provides information for recently displayed ads.
///
/// Please call this method after the SDK has initialized.
///
public static void ShowCreativeDebugger()
{
MaxUnityPluginClass.CallStatic("showCreativeDebugger");
}
///
/// Returns the arbitrary ad value for a given ad unit identifier with key. Returns null if no ad is loaded.
///
/// Ad unit identifier for which to get the ad value for. Must not be null.
/// Ad value key. Must not be null.
/// Arbitrary ad value for a given key, or null if no ad is loaded.
public static string GetAdValue(string adUnitIdentifier, string key)
{
var value = MaxUnityPluginClass.CallStatic("getAdValue", adUnitIdentifier, key);
if (string.IsNullOrEmpty(value)) return null;
return value;
}
#endregion
#region Privacy
///
/// Get the SDK configuration for this user.
///
/// Note: This method should be called only after SDK has been initialized.
///
public static SdkConfiguration GetSdkConfiguration()
{
var sdkConfigurationStr = MaxUnityPluginClass.CallStatic("getSdkConfiguration");
var sdkConfigurationDict = Json.Deserialize(sdkConfigurationStr) as Dictionary;
return SdkConfiguration.Create(sdkConfigurationDict);
}
///
/// Set whether or not user has provided consent for information sharing with AppLovin and other providers.
///
/// true if the user has provided consent for information sharing with AppLovin. false by default.
public static void SetHasUserConsent(bool hasUserConsent)
{
MaxUnityPluginClass.CallStatic("setHasUserConsent", hasUserConsent);
}
///
/// Check if user has provided consent for information sharing with AppLovin and other providers.
///
/// true if user has provided consent for information sharing. false if the user declined to share information or the consent value has not been set .
public static bool HasUserConsent()
{
return MaxUnityPluginClass.CallStatic("hasUserConsent");
}
///
/// Check if user has set consent for information sharing.
///
/// true if user has set a value of consent for information sharing.
public static bool IsUserConsentSet()
{
return MaxUnityPluginClass.CallStatic("isUserConsentSet");
}
///
/// Mark user as age restricted (i.e. under 16).
///
/// true if the user is age restricted (i.e. under 16).
public static void SetIsAgeRestrictedUser(bool isAgeRestrictedUser)
{
MaxUnityPluginClass.CallStatic("setIsAgeRestrictedUser", isAgeRestrictedUser);
}
///
/// Check if user is age restricted.
///
/// true if the user is age-restricted. false if the user is not age-restricted or the age-restriction has not been set.
public static bool IsAgeRestrictedUser()
{
return MaxUnityPluginClass.CallStatic("isAgeRestrictedUser");
}
///
/// Check if the user has set its age restricted settings.
///
/// true if the user has set its age restricted settings.
public static bool IsAgeRestrictedUserSet()
{
return MaxUnityPluginClass.CallStatic("isAgeRestrictedUserSet");
}
///
/// Set whether or not user has opted out of the sale of their personal information.
///
/// true if the user has opted out of the sale of their personal information.
public static void SetDoNotSell(bool doNotSell)
{
MaxUnityPluginClass.CallStatic("setDoNotSell", doNotSell);
}
///
/// Check if the user has opted out of the sale of their personal information.
///
/// true if the user has opted out of the sale of their personal information. false if the user opted in to the sell of their personal information or the value has not been set .
public static bool IsDoNotSell()
{
return MaxUnityPluginClass.CallStatic("isDoNotSell");
}
///
/// Check if the user has set the option to sell their personal information.
///
/// true if user has chosen an option to sell their personal information.
public static bool IsDoNotSellSet()
{
return MaxUnityPluginClass.CallStatic("isDoNotSellSet");
}
#endregion
#region Banners
///
/// Create a new banner.
///
/// Ad unit identifier of the banner to create. Must not be null.
/// Banner position. Must not be null.
public static void CreateBanner(string adUnitIdentifier, BannerPosition bannerPosition)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "create banner");
MaxUnityPluginClass.CallStatic("createBanner", adUnitIdentifier, bannerPosition.ToSnakeCaseString());
}
///
/// Create a new banner with a custom position.
///
/// Ad unit identifier of the banner to create. Must not be null.
/// The X coordinate (horizontal position) of the banner relative to the top left corner of the screen.
/// The Y coordinate (vertical position) of the banner relative to the top left corner of the screen.
///
/// The banner is placed within the safe area of the screen. You can use this to get the absolute position of the banner on screen.
///
public static void CreateBanner(string adUnitIdentifier, float x, float y)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "create banner");
MaxUnityPluginClass.CallStatic("createBanner", adUnitIdentifier, x, y);
}
///
/// Load a new banner ad.
/// NOTE: The method loads the first banner ad and initiates an automated banner refresh process.
/// You only need to call this method if you pause banner refresh.
///
/// Ad unit identifier of the banner to load. Must not be null.
public static void LoadBanner(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "load banner");
MaxUnityPluginClass.CallStatic("loadBanner", adUnitIdentifier);
}
///
/// Set the banner placement for an ad unit identifier to tie the future ad events to.
///
/// Ad unit identifier of the banner to set the placement for. Must not be null.
/// Placement to set
public static void SetBannerPlacement(string adUnitIdentifier, string placement)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set banner placement");
MaxUnityPluginClass.CallStatic("setBannerPlacement", adUnitIdentifier, placement);
}
///
/// Starts or resumes auto-refreshing of the banner for the given ad unit identifier.
///
/// Ad unit identifier of the banner for which to start auto-refresh. Must not be null.
public static void StartBannerAutoRefresh(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "start banner auto-refresh");
MaxUnityPluginClass.CallStatic("startBannerAutoRefresh", adUnitIdentifier);
}
///
/// Pauses auto-refreshing of the banner for the given ad unit identifier.
///
/// Ad unit identifier of the banner for which to stop auto-refresh. Must not be null.
public static void StopBannerAutoRefresh(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "stop banner auto-refresh");
MaxUnityPluginClass.CallStatic("stopBannerAutoRefresh", adUnitIdentifier);
}
///
/// Updates the position of the banner to the new position provided.
///
/// The ad unit identifier of the banner for which to update the position. Must not be null.
/// A new position for the banner. Must not be null.
public static void UpdateBannerPosition(string adUnitIdentifier, BannerPosition bannerPosition)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "update banner position");
MaxUnityPluginClass.CallStatic("updateBannerPosition", adUnitIdentifier, bannerPosition.ToSnakeCaseString());
}
///
/// Updates the position of the banner to the new coordinates provided.
///
/// The ad unit identifier of the banner for which to update the position. Must not be null.
/// The X coordinate (horizontal position) of the banner relative to the top left corner of the screen.
/// The Y coordinate (vertical position) of the banner relative to the top left corner of the screen.
///
/// The banner is placed within the safe area of the screen. You can use this to get the absolute position of the banner on screen.
///
public static void UpdateBannerPosition(string adUnitIdentifier, float x, float y)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "update banner position");
MaxUnityPluginClass.CallStatic("updateBannerPosition", adUnitIdentifier, x, y);
}
///
/// Overrides the width of the banner in dp.
///
/// The ad unit identifier of the banner for which to override the width for. Must not be null.
/// The desired width of the banner in dp
public static void SetBannerWidth(string adUnitIdentifier, float width)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set banner width");
MaxUnityPluginClass.CallStatic("setBannerWidth", adUnitIdentifier, width);
}
///
/// Show banner at a position determined by the 'CreateBanner' call.
///
/// Ad unit identifier of the banner to show. Must not be null.
public static void ShowBanner(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "show banner");
MaxUnityPluginClass.CallStatic("showBanner", adUnitIdentifier);
}
///
/// Remove banner from the ad view and destroy it.
///
/// Ad unit identifier of the banner to destroy. Must not be null.
public static void DestroyBanner(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "destroy banner");
MaxUnityPluginClass.CallStatic("destroyBanner", adUnitIdentifier);
}
///
/// Hide banner.
///
/// Ad unit identifier of the banner to hide. Must not be null.
public static void HideBanner(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "hide banner");
MaxUnityPluginClass.CallStatic("hideBanner", adUnitIdentifier);
}
///
/// Set non-transparent background color for banners to be fully functional.
///
/// Ad unit identifier of the banner to set background color for. Must not be null.
/// A background color to set for the ad. Must not be null.
public static void SetBannerBackgroundColor(string adUnitIdentifier, Color color)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set background color");
MaxUnityPluginClass.CallStatic("setBannerBackgroundColor", adUnitIdentifier, MaxSdkUtils.ParseColor(color));
}
///
/// Set an extra parameter for the banner ad.
///
/// Ad unit identifier of the banner to set the extra parameter for. Must not be null.
/// The key for the extra parameter. Must not be null.
/// The value for the extra parameter.
public static void SetBannerExtraParameter(string adUnitIdentifier, string key, string value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set banner extra parameter");
MaxUnityPluginClass.CallStatic("setBannerExtraParameter", adUnitIdentifier, key, value);
}
///
/// Set a local extra parameter for the banner ad.
///
/// Ad unit identifier of the banner to set the local extra parameter for. Must not be null.
/// The key for the local extra parameter. Must not be null.
/// The value for the extra parameter. Accepts the following types: , null, IList, IDictionary, string, primitive types
public static void SetBannerLocalExtraParameter(string adUnitIdentifier, string key, object value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set banner local extra parameter");
if (value == null || value is AndroidJavaObject)
{
MaxUnityPluginClass.CallStatic("setBannerLocalExtraParameter", adUnitIdentifier, key, (AndroidJavaObject) value);
}
else
{
MaxUnityPluginClass.CallStatic("setBannerLocalExtraParameterJson", adUnitIdentifier, key, SerializeLocalExtraParameterValue(value));
}
}
///
/// The custom data to tie the showing banner ad to, for ILRD and rewarded postbacks via the {CUSTOM_DATA} macro. Maximum size is 8KB.
///
/// Banner ad unit identifier of the banner to set the custom data for. Must not be null.
/// The custom data to be set.
public static void SetBannerCustomData(string adUnitIdentifier, string customData)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set banner custom data");
MaxUnityPluginClass.CallStatic("setBannerCustomData", adUnitIdentifier, customData);
}
///
/// The banner position on the screen. When setting the banner position via or ,
/// the banner is placed within the safe area of the screen. This returns the absolute position of the banner on screen.
///
/// Ad unit identifier of the banner for which to get the position on screen. Must not be null.
/// A representing the banner position on screen.
public static Rect GetBannerLayout(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "get banner layout");
var positionRect = MaxUnityPluginClass.CallStatic("getBannerLayout", adUnitIdentifier);
return GetRectFromString(positionRect);
}
#endregion
#region MRECs
///
/// Create a new MREC.
///
/// Ad unit identifier of the MREC to create. Must not be null.
/// MREC position. Must not be null.
public static void CreateMRec(string adUnitIdentifier, AdViewPosition mrecPosition)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "create MREC");
MaxUnityPluginClass.CallStatic("createMRec", adUnitIdentifier, mrecPosition.ToSnakeCaseString());
}
///
/// Create a new MREC with a custom position.
///
/// Ad unit identifier of the MREC to create. Must not be null.
/// The X coordinate (horizontal position) of the MREC relative to the top left corner of the screen.
/// The Y coordinate (vertical position) of the MREC relative to the top left corner of the screen.
///
/// The MREC is placed within the safe area of the screen. You can use this to get the absolute position Rect of the MREC on screen.
///
public static void CreateMRec(string adUnitIdentifier, float x, float y)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "create MREC");
MaxUnityPluginClass.CallStatic("createMRec", adUnitIdentifier, x, y);
}
///
/// Load a new MREC ad.
/// NOTE: The method loads the first MREC ad and initiates an automated MREC refresh process.
/// You only need to call this method if you pause MREC refresh.
///
/// Ad unit identifier of the MREC to load. Must not be null.
public static void LoadMRec(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "load MREC");
MaxUnityPluginClass.CallStatic("loadMRec", adUnitIdentifier);
}
///
/// Set the MREC placement for an ad unit identifier to tie the future ad events to.
///
/// Ad unit identifier of the MREC to set the placement for. Must not be null.
/// Placement to set
public static void SetMRecPlacement(string adUnitIdentifier, string placement)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set MREC placement");
MaxUnityPluginClass.CallStatic("setMRecPlacement", adUnitIdentifier, placement);
}
///
/// Starts or resumes auto-refreshing of the MREC for the given ad unit identifier.
///
/// Ad unit identifier of the MREC for which to start auto-refresh. Must not be null.
public static void StartMRecAutoRefresh(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "start MREC auto-refresh");
MaxUnityPluginClass.CallStatic("startMRecAutoRefresh", adUnitIdentifier);
}
///
/// Pauses auto-refreshing of the MREC for the given ad unit identifier.
///
/// Ad unit identifier of the MREC for which to stop auto-refresh. Must not be null.
public static void StopMRecAutoRefresh(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "stop MREC auto-refresh");
MaxUnityPluginClass.CallStatic("stopMRecAutoRefresh", adUnitIdentifier);
}
///
/// Updates the position of the MREC to the new position provided.
///
/// The ad unit identifier of the MREC for which to update the position. Must not be null.
/// A new position for the MREC. Must not be null.
public static void UpdateMRecPosition(string adUnitIdentifier, AdViewPosition mrecPosition)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "update MREC position");
MaxUnityPluginClass.CallStatic("updateMRecPosition", adUnitIdentifier, mrecPosition.ToSnakeCaseString());
}
///
/// Updates the position of the MREC to the new coordinates provided.
///
/// The ad unit identifier of the MREC for which to update the position. Must not be null.
/// The X coordinate (horizontal position) of the MREC relative to the top left corner of the screen.
/// The Y coordinate (vertical position) of the MREC relative to the top left corner of the screen.
///
/// The MREC is placed within the safe area of the screen. You can use this to get the absolute position Rect of the MREC on screen.
///
public static void UpdateMRecPosition(string adUnitIdentifier, float x, float y)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "update MREC position");
MaxUnityPluginClass.CallStatic("updateMRecPosition", adUnitIdentifier, x, y);
}
///
/// Show MREC at a position determined by the 'CreateMRec' call.
///
/// Ad unit identifier of the MREC to show. Must not be null.
public static void ShowMRec(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "show MREC");
MaxUnityPluginClass.CallStatic("showMRec", adUnitIdentifier);
}
///
/// Remove MREC from the ad view and destroy it.
///
/// Ad unit identifier of the MREC to destroy. Must not be null.
public static void DestroyMRec(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "destroy MREC");
MaxUnityPluginClass.CallStatic("destroyMRec", adUnitIdentifier);
}
///
/// Hide MREC.
///
/// Ad unit identifier of the MREC to hide. Must not be null.
public static void HideMRec(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "hide MREC");
MaxUnityPluginClass.CallStatic("hideMRec", adUnitIdentifier);
}
///
/// Set an extra parameter for the MREC ad.
///
/// Ad unit identifier of the MREC to set the extra parameter for. Must not be null.
/// The key for the extra parameter. Must not be null.
/// The value for the extra parameter.
public static void SetMRecExtraParameter(string adUnitIdentifier, string key, string value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set MREC extra parameter");
MaxUnityPluginClass.CallStatic("setMRecExtraParameter", adUnitIdentifier, key, value);
}
///
/// Set a local extra parameter for the MREC ad.
///
/// Ad unit identifier of the MREC to set the local extra parameter for. Must not be null.
/// The key for the local extra parameter. Must not be null.
/// The value for the extra parameter. Accepts the following types: , null, IList, IDictionary, string, primitive types
public static void SetMRecLocalExtraParameter(string adUnitIdentifier, string key, object value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set MREC local extra parameter");
if (value == null || value is AndroidJavaObject)
{
MaxUnityPluginClass.CallStatic("setMRecLocalExtraParameter", adUnitIdentifier, key, (AndroidJavaObject) value);
}
else
{
MaxUnityPluginClass.CallStatic("setMRecLocalExtraParameterJson", adUnitIdentifier, key, SerializeLocalExtraParameterValue(value));
}
}
///
/// The custom data to tie the showing MREC ad to, for ILRD and rewarded postbacks via the {CUSTOM_DATA} macro. Maximum size is 8KB.
///
/// MREC Ad unit identifier of the banner to set the custom data for. Must not be null.
/// The custom data to be set.
public static void SetMRecCustomData(string adUnitIdentifier, string customData)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set MREC custom data");
MaxUnityPluginClass.CallStatic("setMRecCustomData", adUnitIdentifier, customData);
}
///
/// The MREC position on the screen. When setting the banner position via or ,
/// the banner is placed within the safe area of the screen. This returns the absolute position of the MREC on screen.
///
/// Ad unit identifier of the MREC for which to get the position on screen. Must not be null.
/// A representing the banner position on screen.
public static Rect GetMRecLayout(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "get MREC layout");
var positionRect = MaxUnityPluginClass.CallStatic("getMRecLayout", adUnitIdentifier);
return GetRectFromString(positionRect);
}
#endregion
#region Interstitials
///
/// Start loading an interstitial.
///
/// Ad unit identifier of the interstitial to load. Must not be null.
public static void LoadInterstitial(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "load interstitial");
MaxUnityPluginClass.CallStatic("loadInterstitial", adUnitIdentifier);
}
///
/// Check if interstitial ad is loaded and ready to be displayed.
///
/// Ad unit identifier of the interstitial to load. Must not be null.
/// True if the ad is ready to be displayed
public static bool IsInterstitialReady(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "check interstitial loaded");
return MaxUnityPluginClass.CallStatic("isInterstitialReady", adUnitIdentifier);
}
///
/// Present loaded interstitial for a given placement to tie ad events to. Note: if the interstitial is not ready to be displayed nothing will happen.
///
/// Ad unit identifier of the interstitial to load. Must not be null.
/// The placement to tie the showing ad's events to
/// The custom data to tie the showing ad's events to. Maximum size is 8KB.
public static void ShowInterstitial(string adUnitIdentifier, string placement = null, string customData = null)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "show interstitial");
if (IsInterstitialReady(adUnitIdentifier))
{
MaxUnityPluginClass.CallStatic("showInterstitial", adUnitIdentifier, placement, customData);
}
else
{
MaxSdkLogger.UserWarning("Not showing MAX Ads interstitial: ad not ready");
}
}
///
/// Set an extra parameter for the ad.
///
/// Ad unit identifier of the interstitial to set the extra parameter for. Must not be null.
/// The key for the extra parameter. Must not be null.
/// The value for the extra parameter.
public static void SetInterstitialExtraParameter(string adUnitIdentifier, string key, string value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set interstitial extra parameter");
MaxUnityPluginClass.CallStatic("setInterstitialExtraParameter", adUnitIdentifier, key, value);
}
///
/// Set a local extra parameter for the ad.
///
/// Ad unit identifier of the interstitial to set the local extra parameter for. Must not be null.
/// The key for the local extra parameter. Must not be null.
/// The value for the extra parameter. Accepts the following types: , null, IList, IDictionary, string, primitive types
public static void SetInterstitialLocalExtraParameter(string adUnitIdentifier, string key, object value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set interstitial local extra parameter");
if (value == null || value is AndroidJavaObject)
{
MaxUnityPluginClass.CallStatic("setInterstitialLocalExtraParameter", adUnitIdentifier, key, (AndroidJavaObject) value);
}
else
{
MaxUnityPluginClass.CallStatic("setInterstitialLocalExtraParameterJson", adUnitIdentifier, key, SerializeLocalExtraParameterValue(value));
}
}
#endregion
#region App Open
///
/// Start loading an app open ad.
///
/// Ad unit identifier of the app open ad to load. Must not be null.
public static void LoadAppOpenAd(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "load app open ad");
MaxUnityPluginClass.CallStatic("loadAppOpenAd", adUnitIdentifier);
}
///
/// Check if app open ad ad is loaded and ready to be displayed.
///
/// Ad unit identifier of the app open ad to load. Must not be null.
/// True if the ad is ready to be displayed
public static bool IsAppOpenAdReady(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "check app open ad loaded");
return MaxUnityPluginClass.CallStatic("isAppOpenAdReady", adUnitIdentifier);
}
///
/// Present loaded app open ad for a given placement to tie ad events to. Note: if the app open ad is not ready to be displayed nothing will happen.
///
/// Ad unit identifier of the app open ad to load. Must not be null.
/// The placement to tie the showing ad's events to
/// The custom data to tie the showing ad's events to. Maximum size is 8KB.
public static void ShowAppOpenAd(string adUnitIdentifier, string placement = null, string customData = null)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "show app open ad");
if (IsAppOpenAdReady(adUnitIdentifier))
{
MaxUnityPluginClass.CallStatic("showAppOpenAd", adUnitIdentifier, placement, customData);
}
else
{
MaxSdkLogger.UserWarning("Not showing MAX Ads app open ad: ad not ready");
}
}
///
/// Set an extra parameter for the ad.
///
/// Ad unit identifier of the app open ad to set the extra parameter for. Must not be null.
/// The key for the extra parameter. Must not be null.
/// The value for the extra parameter.
public static void SetAppOpenAdExtraParameter(string adUnitIdentifier, string key, string value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set app open ad extra parameter");
MaxUnityPluginClass.CallStatic("setAppOpenAdExtraParameter", adUnitIdentifier, key, value);
}
///
/// Set a local extra parameter for the ad.
///
/// Ad unit identifier of the app open ad to set the local extra parameter for. Must not be null.
/// The key for the local extra parameter. Must not be null.
/// The value for the extra parameter. Accepts the following types: , null, IList, IDictionary, string, primitive types
public static void SetAppOpenAdLocalExtraParameter(string adUnitIdentifier, string key, object value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set app open ad local extra parameter");
if (value == null || value is AndroidJavaObject)
{
MaxUnityPluginClass.CallStatic("setAppOpenAdLocalExtraParameter", adUnitIdentifier, key, (AndroidJavaObject) value);
}
else
{
MaxUnityPluginClass.CallStatic("setAppOpenAdLocalExtraParameterJson", adUnitIdentifier, key, SerializeLocalExtraParameterValue(value));
}
}
#endregion
#region Rewarded
///
/// Start loading an rewarded ad.
///
/// Ad unit identifier of the rewarded ad to load. Must not be null.
public static void LoadRewardedAd(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "load rewarded ad");
MaxUnityPluginClass.CallStatic("loadRewardedAd", adUnitIdentifier);
}
///
/// Check if rewarded ad ad is loaded and ready to be displayed.
///
/// Ad unit identifier of the rewarded ad to load. Must not be null.
/// True if the ad is ready to be displayed
public static bool IsRewardedAdReady(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "check rewarded ad loaded");
return MaxUnityPluginClass.CallStatic("isRewardedAdReady", adUnitIdentifier);
}
/// ready to be
/// Present loaded rewarded ad for a given placement to tie ad events to. Note: if the rewarded ad is not ready to be displayed nothing will happen.
///
/// Ad unit identifier of the interstitial to load. Must not be null.
/// The placement to tie the showing ad's events to
/// The custom data to tie the showing ad's events to. Maximum size is 8KB.
public static void ShowRewardedAd(string adUnitIdentifier, string placement = null, string customData = null)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "show rewarded ad");
if (IsRewardedAdReady(adUnitIdentifier))
{
MaxUnityPluginClass.CallStatic("showRewardedAd", adUnitIdentifier, placement, customData);
}
else
{
MaxSdkLogger.UserWarning("Not showing MAX Ads rewarded ad: ad not ready");
}
}
///
/// Set an extra parameter for the ad.
///
/// Ad unit identifier of the rewarded to set the extra parameter for. Must not be null.
/// The key for the extra parameter. Must not be null.
/// The value for the extra parameter.
public static void SetRewardedAdExtraParameter(string adUnitIdentifier, string key, string value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set rewarded ad extra parameter");
MaxUnityPluginClass.CallStatic("setRewardedAdExtraParameter", adUnitIdentifier, key, value);
}
///
/// Set a local extra parameter for the ad.
///
/// Ad unit identifier of the rewarded to set the local extra parameter for. Must not be null.
/// The key for the local extra parameter. Must not be null.
/// The value for the extra parameter. Accepts the following types: , null, IList, IDictionary, string, primitive types
public static void SetRewardedAdLocalExtraParameter(string adUnitIdentifier, string key, object value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set rewarded ad local extra parameter");
if (value == null || value is AndroidJavaObject)
{
MaxUnityPluginClass.CallStatic("setRewardedAdLocalExtraParameter", adUnitIdentifier, key, (AndroidJavaObject) value);
}
else
{
MaxUnityPluginClass.CallStatic("setRewardedAdLocalExtraParameterJson", adUnitIdentifier, key, SerializeLocalExtraParameterValue(value));
}
}
#endregion
#region Rewarded Interstitial
///
/// Start loading an rewarded interstitial ad.
///
/// Ad unit identifier of the rewarded interstitial ad to load. Must not be null.
public static void LoadRewardedInterstitialAd(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "load rewarded interstitial ad");
MaxUnityPluginClass.CallStatic("loadRewardedInterstitialAd", adUnitIdentifier);
}
///
/// Check if rewarded interstitial ad ad is loaded and ready to be displayed.
///
/// Ad unit identifier of the rewarded interstitial ad to load. Must not be null.
/// True if the ad is ready to be displayed
public static bool IsRewardedInterstitialAdReady(string adUnitIdentifier)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "check rewarded interstitial ad loaded");
return MaxUnityPluginClass.CallStatic("isRewardedInterstitialAdReady", adUnitIdentifier);
}
///
/// Present loaded rewarded interstitial ad for a given placement to tie ad events to. Note: if the rewarded interstitial ad is not ready to be displayed nothing will happen.
///
/// Ad unit identifier of the rewarded interstitial to show. Must not be null.
/// The placement to tie the showing ad's events to
/// The custom data to tie the showing ad's events to. Maximum size is 8KB.
public static void ShowRewardedInterstitialAd(string adUnitIdentifier, string placement = null, string customData = null)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "show rewarded interstitial ad");
if (IsRewardedInterstitialAdReady(adUnitIdentifier))
{
MaxUnityPluginClass.CallStatic("showRewardedInterstitialAd", adUnitIdentifier, placement, customData);
}
else
{
MaxSdkLogger.UserWarning("Not showing MAX Ads rewarded interstitial ad: ad not ready");
}
}
///
/// Set an extra parameter for the ad.
///
/// Ad unit identifier of the rewarded interstitial to set the extra parameter for. Must not be null.
/// The key for the extra parameter. Must not be null.
/// The value for the extra parameter.
public static void SetRewardedInterstitialAdExtraParameter(string adUnitIdentifier, string key, string value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set rewarded interstitial ad extra parameter");
MaxUnityPluginClass.CallStatic("setRewardedInterstitialAdExtraParameter", adUnitIdentifier, key, value);
}
///
/// Set a local extra parameter for the ad.
///
/// Ad unit identifier of the rewarded interstitial to set the local extra parameter for. Must not be null.
/// The key for the local extra parameter. Must not be null.
/// The value for the extra parameter. Accepts the following types: , null, IList, IDictionary, string, primitive types
public static void SetRewardedInterstitialAdLocalExtraParameter(string adUnitIdentifier, string key, object value)
{
ValidateAdUnitIdentifier(adUnitIdentifier, "set rewarded interstitial ad local extra parameter");
if (value == null || value is AndroidJavaObject)
{
MaxUnityPluginClass.CallStatic("setRewardedInterstitialAdLocalExtraParameter", adUnitIdentifier, key, (AndroidJavaObject) value);
}
else
{
MaxUnityPluginClass.CallStatic("setRewardedInterstitialAdLocalExtraParameterJson", adUnitIdentifier, key, SerializeLocalExtraParameterValue(value));
}
}
#endregion
#region Event Tracking
///
/// Track an event using AppLovin.
///
/// An event from the list of pre-defined events may be found in MaxEvents.cs as part of the AppLovin SDK framework. Must not be null.
/// A dictionary containing key-value pairs further describing this event.
public static void TrackEvent(string name, IDictionary parameters = null)
{
MaxUnityPluginClass.CallStatic("trackEvent", name, Json.Serialize(parameters));
}
#endregion
#region Settings
///
/// Set whether to begin video ads in a muted state or not.
///
/// Please call this method after the SDK has initialized.
///
/// true if video ads should being in muted state.
public static void SetMuted(bool muted)
{
MaxUnityPluginClass.CallStatic("setMuted", muted);
}
///
/// Whether video ads begin in a muted state or not. Defaults to false.
///
/// Note: Returns false if the SDK is not initialized.
///
/// true if video ads begin in muted state.
public static bool IsMuted()
{
return MaxUnityPluginClass.CallStatic("isMuted");
}
///
/// Toggle verbose logging of AppLovin SDK. If enabled AppLovin messages will appear in standard application log accessible via logcat. All log messages will have "AppLovinSdk" tag.
///
/// true if verbose logging should be enabled.
public static void SetVerboseLogging(bool enabled)
{
MaxUnityPluginClass.CallStatic("setVerboseLogging", enabled);
}
///
/// Whether or not verbose logging is enabled.
///
/// true if verbose logging is enabled.
public static bool IsVerboseLoggingEnabled()
{
return MaxUnityPluginClass.CallStatic("isVerboseLoggingEnabled");
}
///
/// Whether the creative debugger will be displayed on fullscreen ads after flipping the device screen down twice. Defaults to true.
///
/// true if the creative debugger should be enabled.
public static void SetCreativeDebuggerEnabled(bool enabled)
{
MaxUnityPluginClass.CallStatic("setCreativeDebuggerEnabled", enabled);
}
///
/// Enable devices to receive test ads, by passing in the advertising identifier (IDFA/GAID) of each test device.
/// Refer to AppLovin logs for the IDFA/GAID of your current device.
///
/// String list of advertising identifiers from devices to receive test ads.
public static void SetTestDeviceAdvertisingIdentifiers(string[] advertisingIdentifiers)
{
if (IsInitialized())
{
MaxSdkLogger.UserError("Test Device Advertising Identifiers must be set before SDK initialization.");
return;
}
// Wrap the string array in an object array, so the compiler does not split into multiple strings.
object[] arguments = {advertisingIdentifiers};
MaxUnityPluginClass.CallStatic("setTestDeviceAdvertisingIds", arguments);
}
///
/// Whether or not the native AppLovin SDKs listen to exceptions. Defaults to true.
///
/// true if the native AppLovin SDKs should not listen to exceptions.
public static void SetExceptionHandlerEnabled(bool enabled)
{
MaxUnityPluginClass.CallStatic("setExceptionHandlerEnabled", enabled);
}
///
/// Whether or not AppLovin SDK will collect the device location if available. Defaults to true.
///
/// true if AppLovin SDK should collect the device location if available.
public static void SetLocationCollectionEnabled(bool enabled)
{
MaxUnityPluginClass.CallStatic("setLocationCollectionEnabled", enabled);
}
///
/// Set an extra parameter to pass to the AppLovin server.
///
/// The key for the extra parameter. Must not be null.
/// The value for the extra parameter. May be null.
public static void SetExtraParameter(string key, string value)
{
MaxUnityPluginClass.CallStatic("setExtraParameter", key, value);
}
///
/// Get the native insets in pixels for the safe area.
/// These insets are used to position ads within the safe area of the screen.
///
public static SafeAreaInsets GetSafeAreaInsets()
{
// Use an int array instead of json serialization for performance
var insets = MaxUnityPluginClass.CallStatic("getSafeAreaInsets");
// Convert from points to pixels
var screenDensity = MaxSdkUtils.GetScreenDensity();
for (var i = 0; i < insets.Length; i++)
{
insets[i] *= (int) screenDensity;
}
return new SafeAreaInsets(insets);
}
#endregion
#region Private
internal static void SetUserSegmentField(string name, string value)
{
MaxUnityPluginClass.CallStatic("setUserSegmentField", name, value);
}
internal static void SetTargetingDataYearOfBirth(int yearOfBirth)
{
MaxUnityPluginClass.CallStatic("setTargetingDataYearOfBirth", yearOfBirth);
}
internal static void SetTargetingDataGender(String gender)
{
MaxUnityPluginClass.CallStatic("setTargetingDataGender", gender);
}
internal static void SetTargetingDataMaximumAdContentRating(int maximumAdContentRating)
{
MaxUnityPluginClass.CallStatic("setTargetingDataMaximumAdContentRating", maximumAdContentRating);
}
internal static void SetTargetingDataEmail(string email)
{
MaxUnityPluginClass.CallStatic("setTargetingDataEmail", email);
}
internal static void SetTargetingDataPhoneNumber(string phoneNumber)
{
MaxUnityPluginClass.CallStatic("setTargetingDataPhoneNumber", phoneNumber);
}
internal static void SetTargetingDataKeywords(string[] keywords)
{
// Wrap the string array in an object array, so the compiler does not split into multiple strings.
object[] arguments = {keywords};
MaxUnityPluginClass.CallStatic("setTargetingDataKeywords", arguments);
}
internal static void SetTargetingDataInterests(string[] interests)
{
// Wrap the string array in an object array, so the compiler does not split into multiple strings.
object[] arguments = {interests};
MaxUnityPluginClass.CallStatic("setTargetingDataInterests", arguments);
}
internal static void ClearAllTargetingData()
{
MaxUnityPluginClass.CallStatic("clearAllTargetingData");
}
#endregion
#region Obsolete
[Obsolete("This method has been deprecated. Please use `GetSdkConfiguration().ConsentDialogState`")]
public static ConsentDialogState GetConsentDialogState()
{
if (!IsInitialized())
{
MaxSdkLogger.UserWarning(
"MAX Ads SDK has not been initialized yet. GetConsentDialogState() may return ConsentDialogState.Unknown");
}
return (ConsentDialogState) MaxUnityPluginClass.CallStatic("getConsentDialogState");
}
[Obsolete("This method has been deprecated. The AdInfo object is returned with ad callbacks.")]
public static AdInfo GetAdInfo(string adUnitIdentifier)
{
var adInfoString = MaxUnityPluginClass.CallStatic("getAdInfo", adUnitIdentifier);
if (string.IsNullOrEmpty(adInfoString)) return null;
var adInfoDictionary = Json.Deserialize(adInfoString) as Dictionary;
return new AdInfo(adInfoDictionary);
}
#endregion
internal class BackgroundCallbackProxy : AndroidJavaProxy
{
public BackgroundCallbackProxy() : base("com.applovin.mediation.unity.MaxUnityAdManager$BackgroundCallback") { }
public void onEvent(string propsStr)
{
HandleBackgroundCallback(propsStr);
}
}
}