I am developing an Android app with Unity. But I cannot connect to a internet server with it.
Tho this gives false, which is good: Application.internetReachability == NetworkReachability.NotReachable
But when trying to execute this snippet:
IEnumerator testConnection() {
Dictionary<string, string> header = new Dictionary<string, string>();
string userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";
header.Add("User-Agent", userAgent);
WWW www = new WWW("www.google.com", null, header);
yield return www;
// check for errors
if (www.error == null) {
util.debug("works");
} else {
// www.error and www.text both are empty
util.debug("testing: WWW Error: " + www.error + www.text);
}
}
it works via unity editor and windows executable, but not on my android device (v 6) Is there a known solution to this?
Ping also seem to work:
IEnumerator PingGoogle() {
Ping googPing = new Ping("172.217.6.195");
while (!googPing.isDone) {
yield return googPing;
}
util.debug("ping works: " + googPing.time); //I reach this point with the app
}
So i think something is wrong with the WWW
-class?
Android version: 6.0.1
OxygenOS-Version: 3.5.6
Unity version: 5.6.0b3 Personal (64bit)
Edit:
I changed the PlayerSettings (which is the android manifest as far as i can tell) of Internet Access
from Auto
to Require
. No success
Edit2:
It appears that www.error
wasnt empty at all. The Message just got truncated because it was too long for unitys-textelement (my fault). The error was java.net.MalformedURLException: Protocol not found: www.google.de
.
So the only thing that was missing was the protocoll, i.e.: http://
. I found this problem when i tried a suggested solution from the comments.