checking internet connection
<p>I use the following code for checking my internet connection.</p>

<pre><code>private boolean haveNetworkConnection() {
        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() &amp;&amp; ni.isAvailable())
                    haveConnectedWifi = true;
            if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
                if (ni.isConnected() &amp;&amp; ni.isAvailable())
                    haveConnectedMobile = true;
        }
        return haveConnectedWifi || haveConnectedMobile;
    }
</code></pre>

<p>but it says that I have the internet connection connection either the internet connection is disconnected or connected. and this method is called in the middle of the onCreate() method and  closes the application by the "back" button. Please help me on this.</p>
