Setting up Windows Phone
Setting up the change of connectivity is simple on Windows Phone. In MainPage.xaml.cs
, we need to subscribe to the NetworkAvailablityChanged
event as follows:
DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(ChangeDetected);
The ChangeDetected
event is also simple, as shown in the following code:
void ChangeDetected(object sender, NetworkNotificationEventArgs e) { MessageEvents.BroadcastIt("Connection", e.NotificationType==NetworkNotificationType.InterfaceConnected ? true.ToString() : false.ToString()); }
Finally, we need to implement the interface:
void ChangeDetected(object sender, NetworkNotificationEventArgs e) { MessageEvents.BroadcastIt("Connection", e.NotificationType==NetworkNotificationType.InterfaceConnected ? true.ToString() : false.ToString()); } class Connection : IConnectivity { public bool NetworkConnected() { var rv = false; try { var InternetConnectionProfile...