What is default shared preference name?

I’m trying to share some data between java plugin and unity.
I think shared preference is easy way.

I need default name of shared preference what unity using.

Ditto. What would the PlayerPrefs class be reading from on Android?

Before Unity 3.4, it used the ‘standard’ context preferences in private mode; ie new PlayerPrefs(mActivity.getPreferences(Context.MODE_PRIVATE));

thanks erique!

Hi,

When you call getPreferences(Context.MODE_PRIVATE) it seems that unique preferences are created for each activity. In the plugin code the activity name seems to be “com.unity3d.player.UnityPlayerNativeActivity”. I believe it’s a different from the one that is vaild while in mono code.

As a consequence, accessing preferences using getPreferences(Context.MODE_PRIVATE) does not work for me in a plugin code.

Did anyone had this problem before and found a proper way to access PlayerPrefs from Java pluign?

best regards,
Marek.

It was migrated to be Activity-independent in Unity 3.4, to support NativeActivity/regular Activity side-by-side:

// UnityPlayer uses PackageName (bundle identifier) as PlayerPrefs identifier, starting from Unity 3.4.
SharedPreferences packagePrefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);

That snippet comes from the UnityPlayerProxyActivity.java, which comes “open-sourced” with the Unity installation.

1 Like

Works like a charm. Thanks Erique!

best regards,
Marek.

Looks like, in later versions of Unity we need to add .v2.playerprefs to the Android package name.

SharedPreferences unityPrefs = context.getSharedPreferences(context.getPackageName() + ".v2.playerprefs", Context.MODE_PRIVATE);

Any idea which version of Unity does need this since?