Search code examples
c#windows-phone-7

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


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


Solution

  • 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;
    

    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.

    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 :-)

    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.