Mobile Zone is brought to you in partnership with:

Den is a DZone Zone Leader and has posted 460 posts at DZone. You can read more from them at their website. View Full User Profile

Make your Windows Phone 7 application dependent on the network connection type

08.17.2010
| 12371 views |
  • submit to reddit

When you operate with downloads on a Windows Phone 7 device, chances are that the volume of the content to be downloaded will vary. This might cause some issues especially for cases when the download is controlled by the user and not by the developer (therefore the user is able to arbitrarily choose any file to download).

For example, what would happen if the end user decides to download a 4GB file while connected to his cellular data network? Most likely, you don’t want to allow this since there could be bandwidth problems.

To limit the usage, you might want to detect the type of network connection first of all. To do this, there is the NetworkInterface class (member of Microsoft.Phone.Net.NetworkInformation) that exposes the NetworkInterfaceType property. This property represents the type of network connection that is currently used by the Windows Phone 7 device.

You can get the complete list of possible connection types here.

You can check the current network interface by simply calling the property, without explicit class instantiation:

Debug.WriteLine(NetworkInterface.NetworkInterfaceType);

Prior to this, you might want to check whether any network connection is available, via:

NetworkInterface.GetIsNetworkAvailable()

When you run this code in the context of the Windows Phone 7 emulator, the network interface used by Windows will be considered to be the default one. So, for example, if I connect to the Internet via a wireless link, the result will be:

Wireless80211

In case the device is using a cellular data network, it can return this for GSM networks (for example, AT&T):

MobileBroadbandGsm

And this for CDMA networks (for example, Verizon):

MobileBroadbandCdma


When you check for this property, you can easily decide whether you want to allow a certain download to be started or not.

Finally, you can us this property for many other application modules. For example, you could limit specific functionality only to GSM or WiFi connections, like VoIP calls.

Comments

Gabor Dolhai replied on Mon, 2010/10/25 - 4:31pm

Hi, i just published an article about this subject, please read and let me know if you have anything to add, Thanks. http://gdwp7dev.wordpress.com/2010/10/24/zune-detection-and-network-awareness/

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.