java.net.ConnectException: Connection refused
I'm caching images to the persistentdatapath folder after I get them from a URL. Later on I try to get the image from the persistentdatapath with a WWW and it's giving me the error: java.net.ConnectException: Connection refused. It works fine on PC and IOS, but not on Android, here's my code:
string filePath = Application.persistentDataPath + product_id + ".png";
DateTime lastModified = File.GetLastWriteTime(filePath);
if (!File.Exists(filePath) || (DateTime.Now - lastModified).TotalDays >= 30)
{
Debug.Log(File.Exists(filePath));
WWW www = new WWW(url);
yield return www;
productImage.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
File.WriteAllBytes(filePath, www.bytes);
}
else
{
WWW www = new WWW(filePath);
yield return www;
productImage.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
}
I know it's possible to use File.ReadAllBytes, but this appears to be slower compared to the WWW (tested on PC). And I'm also curious as to what I did wrong, any other solution that's fast or better for caching is also welcome :). Thanks
Answer by WolffCheng · Jul 13, 2018 at 12:40 PM
You don't always need a Prefix, but when you do, it is freaking Android.......PUT "file://" in front of your Application.persistentDataPath and BOOMED! You got yourself a goodnight sleep! something like this:
Yourpath = "file://"+ Application.persistentDataPath + ......;
Sorry for being so dramatic, but this made me mad.
I think you saved my hair from turning gray out of stress <3
Answer by RoyalCoder · Mar 17, 2018 at 05:09 PM
Hi Anne, did you found a soltion for this? I have the same problem :(
Your answer

Follow this Question
Related Questions
Cache other scripts 1 Answer
Can I safely delete Unity's caches 0 Answers
Broken Cache after Android 6.0 Upgrade 0 Answers
Switching between development and release build makes Unity ignore gradle cache 0 Answers
HELp cant connect to cache server 0 Answers