Network Information on Windows Phone15 Dec 2011
For one of my projects I needed to retrieve the exact connection type used on the device. I needed to know exactly, if the user was using a 3G or 2G cellular connection.
So, after a quick search I found the following link: Microsoft.Phone.Net.NetworkInformation Namespace.
I guess most of you have used the DeviceNetworkInformation class and especially its NetworkAvailabilityChanged Event, which tells us when a connection has been established or lost. Also, this class allows you to determine if Celular and WiFi data are enabled.
However, I needed more information than this class can provide. Among the listed classes on MSDN, I noticed the NetworkInterfaceList Class.
This class contains an enumerable collection of all currently available network connections on your device.
Plus it provides the following properties for the connection:
|Gets the name of the network interface.
|Gets a description of the network interface.
|Gets the type of the network interface.
|Gets additional information about the type of the network interface.
|Gets the connection state of the network interface.
|Gets the speed of the network interface.
|Gets the characteristics of the network interface.
So, you we simply iterate the collection that we get when using NetworkInterfaceList:
var allNetworks = (new NetworkInterfaceList()).ToList();
for (var i =0; i < allNetworks.Count; i++)
var network = allNetworks.ElementAt(i);
So, now you can easily write a check for specific network types or bandwidth.
Hope this tip will be useful.
If you have any comments or suggestions, feel free to leave them in the comments below.