如何确定设备网络名称和连通性
本文关键字:连通性 网络 何确定 | 更新日期: 2023-09-27 17:55:01
我一直在MSDN http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh487166(v=vs.105).aspx上引用一个示例,该示例允许我确定网络更改和网络属性,例如网络名称,状态等。但是,在网络更新发生之前,我如何获得相同的信息?例如,当我的应用程序加载时,没有检测到网络变化,因此信息目前是空白的。当页面被导航到时,我可以强制NetworkAvailabilityChanged事件触发吗?
// Subscribe to the NetworkAvailabilityChanged event
DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(ChangeDetected);
...
// In this callback, we examine the change that was detected. In this example, we are
// creating a simple information string and adding that to the event list on the UI.
// In a real application, this is where you might adjust your communication connection
// in order to take advantage of a network availability change.
void ChangeDetected(object sender, NetworkNotificationEventArgs e)
{
string change = string.Empty;
switch (e.NotificationType)
{
case NetworkNotificationType.InterfaceConnected:
change = "Connected to ";
break;
case NetworkNotificationType.InterfaceDisconnected:
change = "Disconnected from ";
break;
case NetworkNotificationType.CharacteristicUpdate:
change = "Characteristics changed for ";
break;
default:
change = "Unknown change with ";
break;
}
string changeInformation = String.Format(" {0} {1} {2} ({3})",
DateTime.Now.ToString(), change, e.NetworkInterface.InterfaceName,
e.NetworkInterface.InterfaceType.ToString());
// We are making UI updates, so make sure these happen on the UI thread.
Dispatcher.BeginInvoke(() =>
{
Changes.Add(changeInformation);
UpdateNetworkStatus();
UpdateNetworkInterfaces();
});
}
可以通过DeviceNetworkInformation类获取网络信息。
您可以通过添加
来获得此DeviceNetworkInformation使用Microsoft.Phone.Net.NetworkInformation"; "
这里是从微软获取DeviceNetworkInformation的链接。
希望这对你有帮助。(纠正我,如果我错了,或者如果它不工作)
谢谢。