this Blog is about android developing and For Android Mobiles.
Friday, June 28, 2013
Android to Windows Phone 8: Manage Network Usage
t’s more than likely that a Windows Phone app will need to work with data that resides on the Internet. For example, an app may aggregate data from various news sources using RSS feeds. Consuming this type of data in a Windows Phone app is very similar to consuming it in an Android app. In this post I’ll show you how to manage network usage.
It’s important to consider how your Windows Phone app will access network resources once it has the capability to do so. If your app is going to perform a large number of network operations or transfer large amounts of data (e.g. audio/video streaming) you should allow the user to control when these operations are performed.
In a Windows Phone app you can put the user in control over network usage in four steps. First, create an enumeration representing various states of connectivity:
Second, create a method that leverages the NetworkInterface class to determine if the device the app is running on is connected to a network and, if the device is connected, what kind of network the device is on. The method could look like the following:
4.//Perform some action based on state (e.g. start/stop streaming media, prompt user, etc.)
Finally, in the constructor of your class add an event handler for theNetworkChange.NetworkAddressChanged event. This event fires when the network address changes for a connection. This will allow you to know if a connection has been lost, or if the device has switched to a different type of connection.
You would then use the ConnectivityManager and NetworkInfo classes to determine what type of network the device is connected to. The following code shows how to determine if a device is connected to a Wi-Fi or mobile network: