Problem in detecting Internet Connection in Android
<p>I have created a Android application using Google Maps. Now I want to check whether an internet connection is available or not. I search in Google and finally I got solution through Stackoverflow:</p>

<pre><code>boolean HaveConnectedWifi = false;
boolean HaveConnectedMobile = false;
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo)
    {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                HaveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                HaveConnectedMobile = true;
    }
 &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;   
</code></pre>

<p>I have written my online Google map code if it return true and offline code if it return false.</p>

<p>My problem is its showing an internet connection is available even when it is not. Where have I made a mistake?</p>
