Connection change receiver seems to be missing broadcasts
<p>I have a service that gets called periodically, and if it runs into a network error, it checks the network availability, and if there is no network available, the alarm for that service gets cancelled.  I then use a network connectivity broadcast receiver to monitor network changes so that, when the network becomes available again, it can restart the timer.</p>

<p>However, as a precaution, I also run a watchdog timer service that every 5 minutes it runs just to check and see IF the service should be running.  For instance, if the timer is no longer set and the network IS available, it knows there's a problem.</p>

<p>Well, that's what I've been running into lately, though very rarely.  It's why I keep the watchdog timer around, but I'd still rather know why the alarm timer wasn't restarted.</p>

<p>Here's the network receiver:</p>

<pre><code>public class NetworkConnectivityReceiver extends BroadcastReceiver {

    Context context;

    @Override
    public void onReceive(Context ctx, Intent intent) {

        context = ctx;

        WakeUpManager wakeUpMgr = new WakeUpManager(context);

        if (wakeUpMgr.isWakeUpSet() == false) {
            // Log all messages received while the wakeup is not set and it should be.
            Log.d(TAG, "The timer is not set, and a network change message was received");
        }

        // Check if the network is connected, and if so, then restart the timer
    }
}
</code></pre>

<p>Here is the manifest entry for that receiver:</p>

<pre><code>     &lt;receiver android:name="com.mycom.receivers.NetworkConnectivityReceiver"&gt;
         &lt;intent-filter&gt;
             &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE" /&gt;
            &lt;action android:name="android.net.ConnectivityManager.CONNECTIVITY_ACTION" /&gt;
         &lt;/intent-filter&gt;
      &lt;/receiver&gt;
</code></pre>

<p>I check for network availability by:</p>

<pre><code>public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
    NetworkInfo info = mgr.getActiveNetworkInfo();
    if (info != null &amp;&amp; info.isConnected()) {
        return true;
    }
    else {
        return false;
    }
}
</code></pre>

<p>The last messages I'm seeing in the log are:</p>

<ul>
<li>There are no active networks, cancelling timer</li>
<li>Watchdog service: timer was not set and network IS available</li>
<li>Network info: Connectivity: Type: mobile  Available: true  Connected: true  ConnectedOrConnecting:  true</li>
<li>Watchdog service: starting timer....</li>
</ul>

<p>So, the watchdog is reporting a completely available network connection, but my network connectivity receiver never received that message.</p>
