Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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#?

like image 622
ram Avatar asked Mar 16 '11 13:03

ram


2 Answers

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.

like image 164
Omri Gazitt Avatar answered Nov 07 '22 06:11

Omri Gazitt


take a look at phoney tools, they have class PhoneNetworking for this:

http://wildermuth.com/2011/03/05/Phoney_Tools_Updated_(WP7_Open_Source_Library)

its open source you can check the source code

like image 39
Robert Avatar answered Nov 07 '22 06:11

Robert