In this short tutorial you are going to see how to programmatically query and get the mobile Operator information and settings that are applicable. This feature is pretty much needed in any application that uses internet when to check if the Internet connection is active and if active then need to check if the data is coming from Wifi or service provider and from which service provider and to check if the service provider is local provider or in roaming etc. So with these use cases this feature can be more useful in checking the options that the device is current using to avoid any additional charges.
Ok now the next question is which API provides these information, in Windows Phone SDK we have the DeviceNetworkInformation class provides the information about the Device specific and network specific properties. This class is much more used in all the test cases that we discussed above. With this class there are couple of properties like below which can be utilized to check the Mobile Operator and information about the settings in Windows Phone.
- CellularMobileOperator – This property checks the current service provider information of the operator to which the device is mapped
- IsCellularDataRomingEnabled – This property has the status of the setting which will tell if the operator assigned is in Roaming or Local provider.
Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
var MobileOperatorInfo = DeviceNetworkInformation.CellularMobileOperator;
txtMobOp.Text = MobileOperatorInfo.ToString();
if (DeviceNetworkInformation.IsCellularDataRoamingEnabled)
{
var Status = “Data Roaming enabled.”;
txtRoam.Text = Status.ToString();
}
else
{
var Status = “Data Roaming not enabled.”;
txtRoam.Text = Status.ToString();
}
}
The above code is a very basic operation before we does check the network information if the internet is active or not and to check if the internet is connected to Wifi or Mobile operators etc. These operations are to be checked in real time before you check for the mobile operator which gives you more flexibility in assigning the appropriate setting to the application.