/// <summary> /// Received a notification via BR. /// </summary> /// <param name="context"></param> /// <param name="intent"></param> public override void OnReceive(Context context, Intent intent) { if (intent.Action != ConnectivityManager.ConnectivityAction) { return; } var connectionChangedAction = ConnectionChanged; var newConnection = IsConnected; if (connectionChangedAction != null) { if (newConnection != isConnected) { isConnected = newConnection; connectionChangedAction(new ConnectivityChangedEventArgs { IsConnected = isConnected }); } } var connectionTypeChangedAction = ConnectionTypeChanged; if (connectionTypeChangedAction != null) { var connectionTypes = ConnectivityImplementation.GetConnectionTypes(ConnectivityManager); connectionTypeChangedAction(new ConnectivityTypeChangedEventArgs { IsConnected = newConnection, ConnectionTypes = connectionTypes }); } }
/// <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 connectionChangedAction = ConnectionChanged; var newConnection = IsConnected; if (connectionChangedAction != null) { if (newConnection != isConnected) { isConnected = newConnection; connectionChangedAction(new ConnectivityChangedEventArgs { IsConnected = isConnected }); } } var connectionTypeChangedAction = ConnectionTypeChanged; if (connectionTypeChangedAction != null) { var connectionTypes = ConnectivityImplementation.GetConnectionTypes(ConnectivityManager); connectionTypeChangedAction(new ConnectivityTypeChangedEventArgs { IsConnected = newConnection, ConnectionTypes = connectionTypes }); } }