Exemplo n.º 1
0
        private void UpdateConnected(bool triggerChange = true)
        {
            var remoteHostStatus = _reachability?.RemoteHostStatus();
            var internetStatus   = _reachability?.InternetConnectionStatus();

            var previouslyConnected = _isConnected;

            _isConnected = (internetStatus == ConnectionType.Cellular ||
                            internetStatus == ConnectionType.WiFi) ||
                           (remoteHostStatus == ConnectionType.Cellular ||
                            remoteHostStatus == ConnectionType.WiFi);

            if (triggerChange)
            {
                if (previouslyConnected != _isConnected || _previousInternetStatus != internetStatus)
                {
                    ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs(_isConnected));
                }

                var connectionTypes = this.ConnectionTypes.ToArray();
                ConnectivityTypeChanged?.Invoke(this, new ConnectivityTypeChangedEventArgs(_isConnected, connectionTypes));
            }

            _previousInternetStatus = internetStatus ?? ConnectionType.None;
        }
        /// <summary>
        /// Received a notification via BR.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="intent"></param>
        public override async void OnReceive(Context context, Intent intent)
        {
            if (intent.Action != ConnectivityManager.ConnectivityAction)
            {
                return;
            }

            //await 500ms to ensure that the the connection manager updates
            await Task.Delay(500);

            var newConnection = IsConnected;

            if (newConnection != _isConnected)
            {
                _isConnected = newConnection;

                ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs(_isConnected));
            }


            var connectionTypes = ConnectivityService.GetConnectionTypes(ConnectivityManager);

            ConnectivityTypeChanged?.Invoke(this, new ConnectivityTypeChangedEventArgs(newConnection, connectionTypes));
        }
Exemplo n.º 3
0
 private void CurrentConnectivityTypeChanged(object sender, ConnectivityTypeChangedEventArgs e)
 {
     ConnectivityTypeChanged?.Invoke(sender, e);
 }
Exemplo n.º 4
0
 protected virtual void OnConnectivityTypeChanged(ConnectivityTypeChangedEventArgs e)
 => ConnectivityTypeChanged?.Invoke(this, e);
Exemplo n.º 5
0
 void OnConnectivityTypeChange(object sender, ConnectivityTypeChangedEventArgs e) => ConnectivityTypeChanged?.Invoke(sender, e);