示例#1
0
        public override void OnReceive(Context context, Intent intent)
        {
            ConnectivityManager connectivityManager = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);
            NetworkInfo activeNetInfo = connectivityManager.ActiveNetworkInfo;
            NetworkInfo wifiNetInfo = connectivityManager.GetNetworkInfo(ConnectivityType.Wifi);
            NetworkInfo mobileNetInfo = connectivityManager.GetNetworkInfo(ConnectivityType.Mobile);
            var networkState = new NetworkState() {
                IsNetworkAvailable = (activeNetInfo != null) && activeNetInfo.IsAvailable,
                IsWifiAvailable = (wifiNetInfo != null) && wifiNetInfo.IsAvailable,
                IsCellularAvailable = (mobileNetInfo != null) && mobileNetInfo.IsAvailable
            };

            Console.WriteLine("ConnectionChangeReceiver - active: {0} - wifi: {1} - mobile: {2}", networkState.IsNetworkAvailable, networkState.IsWifiAvailable, networkState.IsCellularAvailable);
            _deviceSpecifications.ReportNetworkStateChange(networkState);
            _messageHub.PublishAsync<ConnectionStatusChangedMessage>(new ConnectionStatusChangedMessage(this) {
                NetworkState = networkState
            });
        }
 public void ReportNetworkStateChange(NetworkState networkState)
 {
     if (OnNetworkStateChanged != null)
         OnNetworkStateChanged(networkState);
 }