Need help opening StreamingAssets PDF on Android

Hello,

In the previous version of my Android app, I’m able to open PDFs that are stored on a website. Users click a button, and the PDF is retrieved. I’d strongly prefer to bundle the PDFs with the app, so users can open the files without being online. In the current version of my app, I’ve saved copies of the PDFs in the StreamingAssets folder. According to this documentation, I need to use UnityWebRequest to access these streaming asset files directly on Android. I can’t figure out how this is supposed to work, and the examples I’ve found haven’t been too useful. Would anyone have a solution or guidance?

My code looks something like this. It works on desktop, but not on Android. The user presses a button in the app, which calls tryCoroutine:

    public void tryCoroutine(string filePath){
        StartCoroutine(openFileOnAndroid(filePath));
    }
  
    private IEnumerator openFileOnAndroid(string filePath) {
        UnityWebRequest www = UnityWebRequest.Get(filePath);
        yield return www.SendWebRequest();
        Application.OpenURL(www.url);
    }

The string filePath would be Path.Combine(Application.streamingAssetsPath, fileName);

–Thanks

Nevermind. I mostly figured it out. I had to save the bytes as a file locally via downloadHandler, then open it. I don’t know if it’s possible to open the bytes as some temp file without actually saving anything to disk. This thread on stackoverflow was also helpful: c# - Download large file - Stack Overflow

The file path for StreamingAssets on Android is an URI that points to a file inside apk. You can try, maybe the pdf viewer can open that URI. If not, then yes, you have to copy file to disk.