wp7的应用中能时刻监测手机的网络连接状态吗,如果网络断开了就给用户一个提示,这个怎么做,给个提示,是不是建一个类,然后每个apppage都引用这个类,还是写在一个地方,只用写一次就可以时时检测????
/// <summary> /// 获取当前网络状态 /// </summary> /// <returns>状态</returns> public static string GetNetStates() { //获取Internet请求的网络类型 var netInfo = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType; switch (netInfo) { case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Ethernet: return NetState.Ethernet; case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MobileBroadbandCdma: return NetState.MobileBroadbandCdma; case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.MobileBroadbandGsm: return NetState.MobileBroadbandGsm; case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.None: return NetState.None; case Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.Wireless80211: return NetState.Wireless80211; default: return NetState.Other; } }
这是我写的方法 你可以拿去用