Tuesday, 24 June 2014

Operator and Network information code in C# and XAML for Windows Phone 8

Introduction:

When you create a Windows Phone app, you might want to get operator and network information for the user’s phone.You can do it by considering the following steps.

Open visual studio and create a Blank Project.


Step 1: Create text blocks inside the grid in MainPage.xaml



<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">   <TextBlock Name="Operator" Margin="20,100,0,0"  FontSize="28" Text="" />   <TextBlock Name="NetWork" Margin="20,150,0,0" FontSize="28" Text="" />   <TextBlock Name="Cellular" Margin="20,200,0,0" FontSize="28" Text="" />   <TextBlock Name="Roaming" Margin="20,250,0,0" FontSize="28" Text="" />   <TextBlock Name="Wifi" Margin="20,300,0,0" FontSize="28" Text="" /> 
</Grid>




Step 2: Add Network Information using directive.


using Microsoft.Phone.Net.NetworkInformation;



Step 3: Place below code in the constructor of the MainPage.xaml.cs


Operator.Text = "Operator: " + DeviceNetworkInformation.CellularMobileOperator;


NetWork.Text = "Network: " + DeviceNetworkInformation.IsNetworkAvailable;


Cellular.Text = "Cellular:" + DeviceNetworkInformation.IsCellularDataEnabled;


Roaming.Text = "Roaming: " + DeviceNetworkInformation.IsCellularDataRoamingEnabled;


Wifi.Text = "WiFi: " + DeviceNetworkInformation.IsWiFiEnabled;


Step 4: Run the application



Click Here to download Sample Project

No comments:

Post a Comment