Skip to content

Commit

Permalink
Fix [#2815](#2815) ApplicationPreferences.SetString NoSuchMethodError
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 547316980
  • Loading branch information
maddevrelgithubbot committed Jul 11, 2023
1 parent 2a810fe commit 7476320
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Google Mobile Ads Unity Plugin Change Log

**************
Version Next
**************

- Fixed [#2815] Setting ApplicationPreferences on Android.

**************
Version 8.4.0
**************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,31 @@ public static ApplicationPreferencesClient Instance

public void SetInt(string key, int value)
{
// TODO (b/290781398): Move the logic into android-library
AndroidJavaClass playerClass = new AndroidJavaClass(Utils.UnityActivityClassName);
AndroidJavaObject activity =
playerClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass preferenceManagerClass =
new AndroidJavaClass(Utils.PreferenceManagerClassName);
AndroidJavaObject sharedPreferences =
preferenceManagerClass.Call<AndroidJavaObject>("getDefaultSharedPreferences");
preferenceManagerClass.CallStatic<AndroidJavaObject>(
"getDefaultSharedPreferences", activity);
AndroidJavaObject sharedPrefsEditor = sharedPreferences.Call<AndroidJavaObject>("edit");
sharedPrefsEditor.Call<AndroidJavaObject>("putInt", key, value);
sharedPrefsEditor.Call("apply");
}

public void SetString(string key, string value)
{
// TODO (b/290781398): Move the logic into android-library
AndroidJavaClass playerClass = new AndroidJavaClass(Utils.UnityActivityClassName);
AndroidJavaObject activity =
playerClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass preferenceManagerClass =
new AndroidJavaClass(Utils.PreferenceManagerClassName);
AndroidJavaObject sharedPreferences =
preferenceManagerClass.Call<AndroidJavaObject>("getDefaultSharedPreferences");
preferenceManagerClass.CallStatic<AndroidJavaObject>(
"getDefaultSharedPreferences", activity);
AndroidJavaObject sharedPrefsEditor = sharedPreferences.Call<AndroidJavaObject>("edit");
sharedPrefsEditor.Call<AndroidJavaObject>("putString", key, value);
sharedPrefsEditor.Call("apply");
Expand Down

0 comments on commit 7476320

Please sign in to comment.