我一直在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();
});
}
答案 0 :(得分:0)
您可以通过DeviceNetworkInformation类获取网络信息。
您可以通过添加此
来获取此DeviceNetworkInformation“使用Microsoft.Phone.Net.NetworkInformation;”
这里是Microsoft的link获取DeviceNetworkInformation。
希望这会有所帮助。(如果我错了,或者如果它不起作用,请纠正我)
谢谢。