To conserver battery in my application, whenever my app needs to sync with the cloud, I first check if the network is available. If no connection is available, I register a network broadcast receiver as follows. But this never gets called.
I'm testing this by putting the device into airplane mode. I see the "Network Receiver ENABLED" message. But after I disable airplane mode, and after my Wifi connects, I expect to see the "Received Network Change Intent" message, and it never appears.
Can anyone point out what I may be doing wrong?
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
networkReceiver = new NetworkReceiver();
registerReceiver(networkReceiver, filter);
Log.d(TAG, "Network Receiver ENABLED");
This is the NetworkReceiver:
public class NetworkReceiver extends BroadcastReceiver {
private static String TAG = NetworkReceiver.class.getSimpleName();
@Override
public void onReceive(Context context_, Intent intent_) {
Log.d(TAG, "Received Network Change Intent");
}
}