1

I load images from my local destination to unity the code is:

    Texture2D imgTexture;
    using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(filePath))
    {
        yield return req.SendWebRequest();
        if (req.isNetworkError)
        {
            Debug.Log(req.error);
        }
        else
        {
            imgTexture = DownloadHandlerTexture.GetContent(req);
        }
    }

it works on pc but when I run on android emulator I get an error

Cannot connect to destination host

the local file directory comes from simple file browsing plugin so I am thinking directory cannot be wrong. is it a permission problem how can I fix this?

eomer
  • 3,514
  • 7
  • 30
  • 42
  • Could you add the value of `filePath` or how you get it? – derHugo May 25 '20 at 12:39
  • As Hugo mentioned we also need your `filePath` variable, my guess would be that you're not pointing it to `jar:file//` on Android, which is required if you want to access folders like the streaming assets. – Remy May 25 '20 at 12:42
  • I am using "simple file browser" plugin.I select the picture and returned file path from emulator is "/storage/emulated/0/Pictures/picture.jpg" – eomer May 25 '20 at 13:00
  • try and checkout https://forum.unity.com/threads/unitywebrequest-for-local-files-on-android-failure.441655/ .. you need something like `jar:file// + filePath` or `file// + filePath` – derHugo May 25 '20 at 13:28
  • thx I will try this – eomer May 25 '20 at 14:08
  • sorry to write back this late file:// works thanks. – eomer May 31 '20 at 15:01

0 Answers0