如何在 Windows Phone 7 中检查 3G、wifi、EDGE、蜂窝网络? [英] How can I check for 3G, wifi, EDGE, Cellular Networks in Windows Phone 7?

查看:21
本文介绍了如何在 Windows Phone 7 中检查 3G、wifi、EDGE、蜂窝网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 C# 在 Windows Phone 7 中检查 3G、wifi、EDGE、蜂窝网络?

How can I check for 3G, wifi, EDGE, Cellular Networks in Windows Phone 7 using C#?

推荐答案

如果您可以使用 Mango (7.1) SDK,并且如果您的场景涉及使用套接字,则有一种简单的方法可以获取连接的 NetworkInterfaceType/SubType 信息你刚刚做了:

If you can use the Mango (7.1) SDK, and if your scenario involves using sockets, there's a trivial way to get the NetworkInterfaceType/SubType information for the connection you just made:

    NetworkInterfaceInfo netInterfaceInfo = socket.GetCurrentNetworkInterface();
    var type = netInterfaceInfo.InterfaceType;
    var subType = netInterfaceInfo.InterfaceSubtype;

无需使用 NetworkInterface.NetworkInterfaceType 属性(众所周知,该属性需要 30 秒才能返回);无需为了确定网络类型而触发主机名解析;无需监听网络变化事件.

No need to use the NetworkInterface.NetworkInterfaceType property (which notoriously takes up to 30sec to return); no need to trigger a hostname resolution just to determine the network type; no need to listen to network change events.

当然,这与 DeviceNetworkInformation.IsNetworkAvailable 或 NetworkInterface.GetIsNetworkAvailable() 结合使用效果最佳 - 无论您是否在网络上,这些调用都会立即返回.如果是,请先连接套接字并在连接时提问:-)

Of course, this works best in conjunction with DeviceNetworkInformation.IsNetworkAvailable or NetworkInterface.GetIsNetworkAvailable() - those calls return immediately whether you're on a network or not. If you are, you connect the socket first and ask questions when it's connected :-)

最后一点:当心 Mango 的 DeviceNetworkInformation.IsWiFiEnabled - 我以为它会返回我是否在 wifi 网络上,但它会返回手机设置中是否打开或关闭 wifi ......不是很有用.

A final note: beware of Mango's DeviceNetworkInformation.IsWiFiEnabled - I thought it would return whether I was on a wifi network, but instead it returns whether wifi is turned on or off in the phone settings... not super useful.

这篇关于如何在 Windows Phone 7 中检查 3G、wifi、EDGE、蜂窝网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆