title: In Unity, how can I open a file (i.e. PDF) in an external app?
body: <p>I'm working on a Unity app right now, and the client wants to be able to allow the user to click a button and have a PDF open on the phone (iOS and Android), but in whatever app they use for reading PDFs and not inside of the Unity app.</p>
  
  <p>I've tried <code>Application.OpenURL("file:///[...]")</code>, and that works in the editor on my Windows desktop (opens PDF in Edge)... but it doesn't open the file on Android (nothing happens to open the file).</p>
  
  <p>Here's what I'm doing:</p>
  
  <pre><code>public string FileName = string.Empty;
  public string FileExtension = string.Empty;
  private string FilePath = string.Empty;
  void Start()
  {
      FilePath = string.Format("{0}/{1}.{2}", Application.persistentDataPath, FileName, FileExtension);
  }
  
  public void OpenFile()
  {
      if (!File.Exists(FilePath))
      {
          var pathRoot = Application.streamingAssetsPath;
          #if UNITY_ANDROID &amp;&amp; !UNITY_EDITOR
              pathRoot = Application.dataPath + "!/assets";
          #endif
          StartCoroutine(FetchFile(string.Format("{0}/{1}.{2}", pathRoot, FileName, FileExtension)));
          return;
      }
      Application.OpenURL(FilePath);
  }
  
  private IEnumerator FetchFile(string path)
  {
      path = "file://" + path;
      #if UNITY_ANDROID &amp;&amp; !UNITY_EDITOR
          path = "jar:" +  path;
      #endif
      var fetcher = new WWW(path);
      yield return fetcher;
      File.WriteAllBytes(FilePath, fetcher.bytes);
  
      Application.OpenURL("file:///" + FilePath);
  }
  </code></pre>
  
  <p>So I'm checking if the file exists on the device in storage, and if not I am 'extracting' it from the app and writing it to storage. Then I try to open the local 'URL' with the <code>file:///</code> standard (this <code>Application.OpenURL("https://www.google.com");</code> does work successfully to open that URL in my mobile browser).</p>
  
  <p>Is there a way in Unity to create an <code>Intent</code> or something to trigger this? The <code>FilePath</code> works on Windows, and is the same path I am writing the bytes to, so that should be correct... or am I missing something?</p>
  
  <p><strong><em>NOTE:</em></strong> this is also not working in iOS, but I thought I read in the Unity forums (can't find the link now) to Android being the only exception to the paths/URL thing... can anyone help me out with that, too?</p>