public void Stop()
        {
            if (broadcastReceiver == null)
            {
                throw new InvalidOperationException("Network status monitoring not active.");
            }

            // Unregister the receiver so we no longer get updates.
            Application.Context.UnregisterReceiver(broadcastReceiver);

            // Set the variable to nil, so that we know the receiver is no longer used.
            broadcastReceiver.ConnectionStatusChanged -= OnNetworkStatusChanged;
            broadcastReceiver = null;
        }
        public void Start()
        {
            if (broadcastReceiver != null)
            {
                throw new InvalidOperationException(
                          "Network status monitoring already active.");
            }

            // Create the broadcast receiver and bind the event handler
            // so that the app gets updates of the network connectivity status
            broadcastReceiver = new NetworkStatusBroadcastReceiver();
            broadcastReceiver.ConnectionStatusChanged += OnNetworkStatusChanged;

            // Register the broadcast receiver
            Application.Context.RegisterReceiver(broadcastReceiver,
                                                 new IntentFilter(ConnectivityManager.ConnectivityAction));
        }