In this article we will find out how to get mobile operator information and how to get network capabilities like Network availability, Cellular Data, Roaming and WiFi of a mobile running Windows Phone 7. We will use DeviceNetworkInformation class of Microsoft.Phone.Net.NetworkInformation.
Let's write code to check this out:
Step 1: Place 5 textblocks inside the grid in MainPage.xaml.cs.
< Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <TextBlock Name="txtOperator" Margin="20,100,0,0" FontSize="28" Text="" /> <TextBlock Name="txtNetWork" Margin="20,150,0,0" FontSize="28" Text="" /> <TextBlock Name="txtCellular" Margin="20,200,0,0" FontSize="28" Text="" /> <TextBlock Name="txtRoaming" Margin="20,250,0,0" FontSize="28" Text="" /> <TextBlock Name="txtWifi" Margin="20,300,0,0" FontSize="28" Text="" /> </Grid>
Step 2: Add NetworkInformation using directive.
using Microsoft.Phone.Net.NetworkInformation;
Step 3: Place below code in the constructor of the MainPage.
txtOperator.Text = "Operator: " + DeviceNetworkInformation.CellularMobileOperator;
txtNetWork.Text = "Network: " + DeviceNetworkInformation.IsNetworkAvailable;
txtCellular.Text = "Cellular:" + DeviceNetworkInformation.IsCellularDataEnabled;
txtRoaming.Text = "Roaming: " + DeviceNetworkInformation.IsCellularDataRoamingEnabled;
txtWifi.Text = "WiFi: " + DeviceNetworkInformation.IsWiFiEnabled;
Step 4: Run the application.
This ends the article of finding operator information and network capabilities of mobile running Windows Phone 7.
|