Save an image to PersistentDataPath then access it again

I want to use a button to take a screenshot and save it the the PersistentDataPath on an Android device.
Then on another button press, I want to get that image and apply it as a Texture.

So far, I can successfully take the screenshot and save it (with use of a plugin) but I can’t seem to access it afterwards; the texture just shows a red question mark.

I’ve tested with pulling existing images from my Desktop and StreamingAssets, which works fine, but it seems to have an issue doing it during runtime.

When I save the image, it goes to this file path on the Android device: /storage/emulated/0/Android/data/[my bundle identifier]/files/ScreenshotApp/MyScreenshot.jpg

The script I’m using to retrieve the image from the Android Persistent Data Path:

  private IEnumerator GetImage()
    {
     string url = "file:///" + Application.persistentDataPath + "/MyScreenshot.jpg"; 
byte[] imgData;
         UnityWebRequest www = UnityWebRequest.Get(url);
        yield return www.SendWebRequest();
        imgData = www.downloadHandler.data;

        if (www.error != null)
        {
            Debug.LogError(www.error);
            console.text = www.error;
            console.text += url;
            }
        print(url);

Texture2D tex = new Texture2D(20, 20);
    tex.LoadImage(imgData);
quad.GetComponent<Renderer>().material.mainTexture = tex;        
    }

The pathway that the console returns, is the same as above.

I’ve tried changing the prefix to the pathway to “file://”, “file:///”, “jar:file:///” and removing the prefix altogether but nothing seems to work.

If I use “file:///” it displays the error: Unable to read data.

Using “file://” returns the error: HTTP/1.1 404 Not Found

Using “jar:file://” returns the error: HTTP/1.1 404 Not Found

If there is no prefix it shows: Unknown Error

All of them show the red question mark.

I would appreciate anyones input on this.

Thanks in advance.

I think the error is because your texture is unreadable. Whenever you are generating the texture/ taking the screenshot make sure the “non readable” property of the texture is set to false.
If you are using a plugin, it should have a boolean parameter to set the texture readable.