Exemple #1
0
 void IDisposable.Dispose()
 {
     if (_manager != null)
     {
         _manager.UnregisterNetworkCallback(this);
     }
 }
Exemple #2
0
 public WifiHandler()
 {
     this.context         = Android.App.Application.Context;
     _connectivityManager = Application.Context.GetSystemService(Context.ConnectivityService) as ConnectivityManager;
     _callback            = new NetworkCallback
     {
         NetworkAvailable = network =>
         {
             // we are connected!
             _callbackStatus = $"Requested network connected";
             _connectivityManager.BindProcessToNetwork(network);
             Static.RuntimeSettings.IsWifiRequestingFinished = true;
         },
         NetworkUnavailable = () =>
         {
             _callbackStatus = $"Requested network unavailable";
             Static.RuntimeSettings.IsWifiRequestingFinished = true;
         },
         NetworkLost = network =>
         {
             _callbackStatus = $"Requested network lost";
             _connectivityManager.BindProcessToNetwork(null);
             _connectivityManager.UnregisterNetworkCallback(_callback);
         }
     };
 }
Exemple #3
0
        private void UnregisterNetworkCallback()
        {
            if (connectivityCallback == null)
            {
                return;
            }

            ConnectivityManager connManager = (ConnectivityManager)GetSystemService(Context.ConnectivityService);

            if (connManager != null)
            {
                connManager.UnregisterNetworkCallback(connectivityCallback);
                connectivityCallback = null;
            }
        }
Exemple #4
0
        public void Disconnect()
        {
            this.msgPump.Disconnect();
            if (this.connectCallback != null)
            {
                // Some note that sometimes you need to force un-bind
                ConnectivityManager cm = this.GetConnectivityManager();
                cm.BindProcessToNetwork(null);
                cm.UnregisterNetworkCallback(this.connectCallback);
                this.connectCallback.Dispose();
                this.connectCallback = null;
            }

            if (this.network != null)
            {
                this.network.Dispose();
                this.network = null;
                // Bug in the connect callback returns immediately if socket
                // is still detected. Then a second time. Looks like time is
                // required to shut down but no synchronisation is provided
                Thread.Sleep(100);
            }
        }