[Application.internetReachability][1] always returns [NetworkReachability.NotReachable][2] on my Android 2.1. Works as expected in Editor. I also tried using the [Ping][3] class to detect internet availability using the following C# code.
----------
IEnumerator CheckConnection()
{
const float timeout = 10f;
float startTime = Time.timeSinceLevelLoad;
Ping ping = new Ping("199.59.148.82");
while (true)
{
internetAvailableText = "Checking network...";
if (ping.isDone)
{
internetAvailableText = "Network available.";
yield break;
}
if (Time.timeSinceLevelLoad - startTime > timeout)
{
internetAvailableText = "No network.";
yield break;
}
yield return new WaitForEndOfFrame();
}
}
----------
It always timed out. [WWW][4] class works as expected. Anyone had luck detecting internet access on Android?
[1]: http://unity3d.com/support/documentation/ScriptReference/Application-internetReachability.html
[2]: http://unity3d.com/support/documentation/ScriptReference/NetworkReachability.html
[3]: http://unity3d.com/support/documentation/ScriptReference/Ping.html
[4]: http://unity3d.com/support/documentation/ScriptReference/WWW.html
↧