PlayerPref from App.xaml.cs

Hi,
I have overrided the void OnActivated(IActivatedEventArgs args) on App.xaml.cs in order to get the URL from the specific file i want to open on my app.

Now i want to set this URL on the PlayerPref in Unity.
Any ideas how i can do that ?

I know that we can do this on IOS so maybe it’s the same on Metro…

You already reference UnityEngine.dll from your application, so you can access UnityEngine.PlayerPrefs without problems.

But, I am guessing OnActivated event will be called before Unity is initialized, so do this:

  • Subscribe to appCallbacks.Initialized event, which is called when Unity is initalized
  • Save URL in some variable in App.xaml.cs
  • In your initialized callback, write something like:
    appCallbacks.InvokeOnAppThread(new AppCallbackItem(() =>
    {
    UnityEngine.PlayerPrefs.SetString(“URL”, myURL);
    }
    ), false);

Hope that helps.