Skip to content

Commit

Permalink
Refactor the UnityPlayer activity class name into a local constant in…
Browse files Browse the repository at this point in the history
… the AppLovin Unity plugin's Android client class.

PiperOrigin-RevId: 646998307
  • Loading branch information
Mobile Ads Developer Relations authored and maddevrelgithubbot committed Jun 26, 2024
1 parent 4c6c44e commit fbda9fa
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,32 @@ namespace GoogleMobileAds.Mediation.AppLovin.Android
{
public class AppLovinClient : IAppLovinClient
{
private static AppLovinClient instance = new AppLovinClient();
private AppLovinClient() {}

private static readonly AppLovinClient instance = new AppLovinClient();
private const string appLovinSdkClassName = "com.applovin.sdk.AppLovinSdk";
private const string appLovinPrivacySettingsClassName =
"com.applovin.sdk.AppLovinPrivacySettings";
private const string UnityActivityClassName = "com.unity3d.player.UnityPlayer";

public static AppLovinClient Instance
{
get {
get
{
return instance;
}
}

private AppLovinClient() { }

public void Initialize()
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity =
unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject currentActivity = getCurrentActivityAndroidJavaObject();
AndroidJavaClass appLovin = new AndroidJavaClass(appLovinSdkClassName);
appLovin.CallStatic("initializeSdk", currentActivity);
}

public void SetHasUserConsent(bool hasUserConsent)
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity =
unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject currentActivity = getCurrentActivityAndroidJavaObject();
AndroidJavaClass appLovinPrivacySettings =
new AndroidJavaClass(appLovinPrivacySettingsClassName);
appLovinPrivacySettings.CallStatic("setHasUserConsent", hasUserConsent,
Expand All @@ -57,9 +55,7 @@ public void SetHasUserConsent(bool hasUserConsent)

public void SetIsAgeRestrictedUser(bool isAgeRestrictedUser)
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity =
unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject currentActivity = getCurrentActivityAndroidJavaObject();
AndroidJavaClass appLovinPrivacySettings =
new AndroidJavaClass(appLovinPrivacySettingsClassName);
appLovinPrivacySettings.CallStatic("setIsAgeRestrictedUser", isAgeRestrictedUser,
Expand All @@ -68,13 +64,21 @@ public void SetIsAgeRestrictedUser(bool isAgeRestrictedUser)

public void SetDoNotSell(bool doNotSell)
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity =
unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject currentActivity = getCurrentActivityAndroidJavaObject();
AndroidJavaClass appLovinPrivacySettings =
new AndroidJavaClass(appLovinPrivacySettingsClassName);
appLovinPrivacySettings.CallStatic("setDoNotSell", doNotSell, currentActivity);
}

// Private utility methods

private AndroidJavaObject getCurrentActivityAndroidJavaObject()
{
AndroidJavaClass unityPlayer = new AndroidJavaClass(UnityActivityClassName);
AndroidJavaObject currentActivity =
unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
return currentActivity;
}
}
}

Expand Down

0 comments on commit fbda9fa

Please sign in to comment.