0

WebClient class is giving different result in Editor and in Android build.

    void Start () {
        path = Application.persistentDataPath;
#if UNITY_EDITOR
        path = "D:/data";
#endif

        client.DownloadProgressChanged += Progress;
        client.DownloadFileCompleted += Completed;
        client.DownloadFileAsync (new Uri(url), path+"/version");
    }

    public void Progress(object sender, DownloadProgressChangedEventArgs e)
    {
        Debug.Log(e.ProgressPercentage);
    }

    public void Completed(object sender, AsyncCompletedEventArgs e)
    {
        if (e.Error != null || e.Cancelled) {
            Debug.Log(e.Error.Message);
        } 
        else
        {
            Debug.Log("Successfully Completed");
        }
    }

When run from Unity Editor the file was downloaded fine. But when build for Android it gives a error message as Name Resolution Failure.

It gives the same error when there is no Internet Connection when running on Unity Editor. But I get the error message in Android whether the device is connected to internet or not.

8
  • what's the value of url? Commented Jan 9, 2019 at 13:26
  • It's the string that contains the download URL to a binary file. I don't think it is a problem in the URL because the file is downloading when in unity editor Commented Jan 9, 2019 at 13:37
  • ok .. is D:/data a folder or the file? Commented Jan 9, 2019 at 13:38
  • did you try using Path.Combine? Commented Jan 9, 2019 at 13:48
  • 3
    Problem was actually not in WebClient class its because my apk didnt have the permission to access internet. I just had to change the Internet Access in Player Settings from auto to require as I was using WebClient instead of WWW class.Thanks derHugo for helping out. Commented Jan 9, 2019 at 14:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.