Synchronise Android Preferences with Unity

Hello guys, long time. I have a simple request, hopefully you guys can help.

I’m completely new to Eclipse. So I want to make Android Preferences for the user and sync their values with Unity in a couple of scripts’ Start() functions. I’ve achieved this in iOS. I’m talking about doing the iOS equivalent of:

-Create Settings.Bundle
-In UnityAppDelegate.mm’s OnViewDidLoad void, I synchronise them like so
[defaults setObject:to_sync_with_Unity forKey:@“from_settings_bundle”];
-Get them in PlayerPrefsGetInt(“to_sync_with_Unity”);

So I’ve made a preferences.xml in the res folder [equivalent of creating Settings.Bundle]. Doing all in Eclipse. How do I go about these? I beg you, I need to do this before Tuesday. Thanks a lot.

Hi, you need to write a plugin for that, check out unity’s official page
From java side you want something like this I guess?

package com.company.product;

import com.unity3d.player.UnityPlayerActivity;

import android.os.Bundle;
import android.util.Log;

public class OverrideExample extends UnityPlayerActivity {

  protected void onCreate(Bundle savedInstanceState) {

    // call UnityPlayerActivity.onCreate()
    super.onCreate(savedInstanceState);

    // print debug message to logcat
    Log.d("OverrideActivity", "onCreate called!");
    // get your saved data
    SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    long highScore = sharedPref.getInt("to_sync_with_Unity"), defaultValue);
    Log.d("OverrideActivity", "val: "+highScore);
  }
}