Floating FB popout byF5debug

101 How to on Windows Phone – How to #33 – Get Mobile Operator details in Windows Phone

 

In this tutorial we are going to see how we can get the mobile operator details in Windows Phone Application development. In order to get the mobile operator information we are going to use the API class which is DeviceNetworkInformation class. This class has information on the network details of the specific device from which its called. Since this class is static we can directly make use of this class without creating any instance of the same, by using some of the properties that are available by default.        [more]

DeviceNetworkInformation Class has some list of properties by default using which we can collect the information of the specified device which will be very used for system monitoring. Below is the list of properties that can be used to get the details

S No

Property Name

Property Description

1

CellularMobileOperator

Fetches the Mobile Operator name

2

IsCellularDataEnabled

Checks if the Mobile operator with a value on Data enabled

3

IsCellularDataRoamingEnabled

Checks if the Mobile Operator network allows roaming or not

4

IsNetworkAvailable

Checks if the network is available or not

5

IsWiFiEnabled

Checks if the Wifi is enabled or not over the network.

So we are going to make use of these properties to check the availability of the network and play around with the properties one by one. To start with Open Visual Studio 2010 IDE and create a new Silverlight for Windows Phone project with a valid project name as shown in the screen below. Once the project is created add some controls which are used to show the details of the network operations as shown in the screen below.

clip_image002

Now drag and drop few controls to the screen which are used to get the details of the network operator and other stuffs. Once we designed the screen to show the desired result our screen looks like below.

clip_image004

Now we need to write our code behind which basically takes the DeviceNetworkInformation class to get the required details one by one as shown in the code below. Before that we need to add the below using statement in order to make use of the DeviceNetworkInformation class properties.

using Microsoft.Phone.Net.NetworkInformation;

Now add the below code sample which just calls the DeviceNetworkInformation class (we are not creating an instance of the class as its static) with the properties as shown in the code below.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Net.NetworkInformation;

namespace F5debugHowto33
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            textBlock1.Text = "Mobile Operator :- " + DeviceNetworkInformation.CellularMobileOperator.ToString();
            textBlock2.Text = "Network Available :- " + DeviceNetworkInformation.IsNetworkAvailable.ToString();
            textBlock3.Text = "Roaming Available :- " + DeviceNetworkInformation.IsCellularDataRoamingEnabled.ToString();
            textBlock4.Text = "Wifi Available :- " + DeviceNetworkInformation.IsWiFiEnabled.ToString();
            textBlock5.Text = "Cellular Data Available :- " + DeviceNetworkInformation.IsCellularDataEnabled.ToString();
        }
    }
}

clip_image006

These are the basic properties which can be used in such a way to gather the information of the network mobile operator, say for example when there is a change in the operator and some notification need to be handled. In those cases we can use the NetworkAvailabilityChanged event to see if there is any change in the network operator.

Now we are done with our code, just run the application by pressing F5 directly from the keyboard or we can use the Build and execute the project option from the tool bar to run the application. Once the Build is successful we can see the Windows Phone emulator with the application and the expected outputs as shown in the screens below.

Output Screens:

clip_image008

So we have seen how to get the mobile operator details and the network details using the DeviceNetworkInformation class and also we have seen the event that is used to notify when there is any change in the network operator or the mobile operator. That’s it from this tutorial on Windows Phone see you all in the next tutorial soon. Mean while Happy Programming!!!

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter