How to ensure if internet is working fine in android
<pre><code>public boolean isNetworkConnected() {
    ConnectivityManager cm =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null &amp;&amp; netInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}
</code></pre>

<p>This function works fine whenever my Internet is connected or disconnected. But there is a scenario when my internet is connected but due to some problem in the internet we are unable to exchange packets or you can say unable to browse. Even in that state I get <code>true</code> from this function, whereas I want to return <code>true</code> only when my internet is working perfectly fine.</p>

<p>What can I do in this scenario? Thanks.</p>
