public override void OnReceive(Context context, Intent intent) { if (intent.Action == "android.net.conn.CONNECTIVITY_CHANGE") { ConnectivityChanged?.Invoke(this, EventArgs.Empty); } }
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> /// When connectivity changes /// </summary> /// <param name="e"></param> protected virtual void OnConnectivityChanged(ConnectivityChangedEventArgs e) { if (ConnectivityChanged != null) { ConnectivityChanged.Invoke(this, e); } }
private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e) { ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs() { IsConnected = e.IsConnected }); }
private async Task CheckConnectivityChanged() { var connected = Connected; Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connectivity has changed - waiting for activity to settle ({DEBOUNCE_DELAY}ms...(Old value: {connected})"); try { _StateDate = DateTime.Now; // wait for things to settle await Task.Delay(DEBOUNCE_DELAY); if (DateTime.Now.Subtract(_StateDate).TotalMilliseconds < DEBOUNCE_DELAY) { return; } Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connectivity has changed..."); // check connection state var hasConnection = !((_NetworkService.ConnectionState == NetworkConnectionStates.None) || (_NetworkService.ConnectionState == NetworkConnectionStates.Unknown)); // check if we are able to ping our backend if (!hasConnection) { Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connectivity has changed - NOT connected to the internet..."); Connected = hasConnection; if (!Initialized) { Initialized = true; } return; } Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connected to internet, Pinging backend..."); var result = await _RestService.PingAsync(); Connected = result; Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Ping success: {Connected}..."); if (!Initialized) { Initialized = true; } } catch { /* do nothing */ } finally { if (connected != Connected) { Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connectivity has changed, raising event."); ConnectivityChanged?.Invoke(this, new EventArgs()); } else { Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Nothing has changed."); } } }
private void OnConnectivityChanged(object sender, ConnectivityChangedEventArgs e) { ConnectionStatusChangedArgs args; if (e.IsConnected) { args = ConnectionStatusChangedArgs.ConnectionGained(); } else { args = ConnectionStatusChangedArgs.ConnectionLost(); } ConnectivityChanged?.Invoke(this, args); }
/// <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)); }
private void OnConnectivityChanged(object sender, Xamarin.Essentials.ConnectivityChangedEventArgs e) { ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs((NetworkAccessEnum)e.NetworkAccess, GetProfiles(e.Profiles))); }
private void Current_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e) { ConnectivityChanged?.Invoke(e.IsConnected); }
internal static void OnConnectivityChanged(ConnectivityStates connectivity) => ConnectivityChanged?.Invoke(connectivity);
protected virtual void OnConnectivityChanged(ConnectivityChangedEventArgs e) => ConnectivityChanged?.Invoke(this, e);
private void OnConnectivityChanged(object sender, ConnectivityChangedEventArgs e) { IsConnected = e.IsConnected; ConnectivityChanged?.Invoke(this, EventArgs.Empty); }
private void OnConnectivityChanged(Data.Models.EventArgs.ConnectivityChangedEventArgs e) { ConnectivityChanged?.Invoke(this, e); }
private void _nlm_NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity) { ConnectivityChanged?.Invoke(this, IsNetworkAvailable()); }
/// <summary> /// Bind to IConnectivity network events. /// </summary> /// <param name="crossConnectivity">The IConnectivity network events instance.</param> private void SubscribeEvents() { Connectivity.ConnectivityChanged += (sender, args) => ConnectivityChanged?.Invoke(this, args); //crossConnectivity.ConnectivityTypeChanged += (sender, args) => ConnectivityTypeChanged?.Invoke(this, args); }
void OnConnectivityChange(object sender, ConnectivityChangedEventArgs e) => ConnectivityChanged?.Invoke(sender, e);
private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e) { ConnectivityChanged?.Invoke(e); }
private void CurrentConnectivityChanged(object sender, ConnectivityChangedEventArgs e) { ConnectivityChanged?.Invoke(sender, e); }
public void SetNetworkAccess(NetworkAccess networkAccess) { NetworkAccess = networkAccess; ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs(NetworkAccess, ConnectionProfiles)); }