Know when network connectivity returns
<p>I have an application that tries to be a good samaritan, basically when any services starts that needs to interact with the network.  I am checking to see if the device has connectivity:</p>

<p><strong>hasConnectivity Method</strong></p>

<pre><code>private boolean hasConnectivity() {
    NetworkInfo info = mConnectivity.getActiveNetworkInfo();
    boolean connected = false;
    int netType = -1; 
    int netSubtype = -1; 

    if (info == null) {
        Log.w(sTag, "network info is null");
        notifyUser(MyIntent.ACTION_VIEW_ALL, "There is no network connectivity.", false);
    } else if (!mConnectivity.getBackgroundDataSetting()) {
        Log.w(sTag, "background data setting is not enabled");
        notifyUser(MyIntent.ACTION_VIEW_ALL, "background data setting is disabled", false);
    } else {
        netType = info.getType();
        netSubtype = info.getSubtype();

        if (netType == ConnectivityManager.TYPE_WIFI) {
            connected = info.isConnected();
        } else if (netType == ConnectivityManager.TYPE_MOBILE
                   &amp;&amp; netSubtype == TelephonyManager.NETWORK_TYPE_UMTS
                   &amp;&amp; !mTelephonyManager.isNetworkRoaming()
                  ) { 
            connected = info.isConnected();
        } else if (info.isRoaming()) {
            notifyUser(MyIntent.ACTION_VIEW_ALL, "Currently Roaming skipping check.", false);
        } else if (info.isAvailable()) {
            connected = info.isConnected();
        } else {
            notifyUser(MyIntent.ACTION_VIEW_ALL, "..There is no network connectivity.", false);
        }   
    }   
    return connected;
} 
</code></pre>

<p>When this method returns false I know that I don't have a connection because the user is on the phone or 3g and wifi is not available</p>

<p>What is the best way to know when Connectivity is available with out pulling the network stats with a timer periodically?</p>

<p>Is there an Intent action that I can observe with a broadcast receiver that will announce a change with connectivity?</p>

<p>Thanks for any help, I will keep searching the docs for some clue on what to do next.</p>
