title: Android Unity c# : UnauthorizedAccessException writing save game data
body: <p>I'm debugging a Unity game in Android, everything works in the Unity editor. I'm receiving an UnauthorizedAccessException when saving the current game data on Android. </p>
  
  <p>I am writing to the persistentDataPath so I don't understand why access is being blocked.</p>
  
  <p>Here is the console log using Logcat:</p>
  
  <pre><code>&lt;i&gt;AndroidPlayer(motorola_Moto_G_(5)@192.168.0.26)&lt;/i&gt; UnauthorizedAccessException: 
  Access to the path "/current.sg" is denied.
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x0028a] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:320 
    at System.IO.FileStream..ctor (System.String path, FileMode mode) [0x00000] in &lt;filename unknown&gt;:0 
    at SaveLoadManager.SaveGame (.Game currentGame) [0x0002a] in F:\Work\Magister\Magister\Magister\Assets\Scripts\SaveLoadManager.cs:16 
    at PlayerController.FixedUpdate () [0x0058e] in F:\Work\Magister\Magister\Magister\Assets\Scripts\PlayerController.cs:244 
  </code></pre>
  
  <p>The relevant code from PlayerController running in a FixedUpdate() loop:</p>
  
  <pre><code>if (!gameSaved)
  {
      SaveLoadManager.SaveGame(gameManager.GetComponent&lt;Game&gt;());
      gameSaved = true;
  }
  </code></pre>
  
  <p>The SaveGame function from SaveLoadManager: </p>
  
  <pre><code>public static void SaveGame(Game currentGame)
  {
      string saveGameFileName = Path.DirectorySeparatorChar + "current.sg";
      string filePath = Path.Combine(Application.persistentDataPath, saveGameFileName);
      BinaryFormatter bf = new BinaryFormatter();
      FileStream file = new FileStream(filePath, FileMode.Create);
      GameData data = new GameData(currentGame);
      bf.Serialize(file, data);
      file.Close();
  }
  </code></pre>
  
  <p>The read/write permissions in the AndroidManifest.xml:</p>
  
  <pre><code>&lt;uses-permission
      android:name="android.permission.WRITE_EXTERNAL_STORAGE"
      android:maxSdkVersion="18" /&gt;
  
  &lt;uses-permission
      android:name="android.permission.READ_EXTERNAL_STORAGE"
      android:maxSdkVersion="18" /&gt;
  </code></pre>