How can you Add Network Connection Settings Page in your WP7 Application?


Do you want to integrate the network connection settings page (like: Airplane, Bluetooth, Cellular and/or WiFi) in your Windows Phone 7 application? Then this article will help you step-by-step to understand and integrate it.

 

Connection Settings page are those, where you can configure your connection types and various parameters of the connection. Windows Phone 7 SDK exposes the APIs for you to integrate them in your application. In this tutorial, we will discuss about these with a nice demo. Read further to know about these settings page and integration steps to the application.

 

Create Demo UI

Let us create the UI design of our demo application, where we will have 4 buttons (as shown in the figure below).

 

The four buttons will open up settings page for Airplane mode, Bluetooth mode, Cellular mode and WiFi mode respectively.

We will also register the click event for each button, so that we can handle respective click events to open up proper settings page easily.

Here is our sample XAML code, where we placed the four buttons:


Demo - Settings Page Launcher UI

 

Once our main demo page is ready, we can go further with the API calls to bring up the settings page. Continue reading on this topic.

 

Know About the APIs

Before going to the depth, we need to know about the APIs first. The namespace “Microsoft.Phone.Tasks” has one sealed class named “ConnectionSettingsTask” and one enumerator called “ConnectionSettingsType”. ConnectionSettingsTask has a property called ConnectionSettingsType and a method called Show().

 

You need to set proper connection type in the ConnectionSettingsType property to open up the respective settings page. The Show() method of the class ConnectionSettingsTask opens the proper page in the UI.

 

Have a look into the API declaration below:

 
namespace Microsoft.Phone.Tasks
{
    public sealed class ConnectionSettingsTask
    {
        public ConnectionSettingsTask();
        public ConnectionSettingsType ConnectionSettingsType { get; set; }
        public void Show();
    }
 
    public enum ConnectionSettingsType
    {
        WiFi = 0,
        Bluetooth = 1,
        Cellular = 2,
        AirplaneMode = 3,
    }
}

 

In the above code snippet, you will easily understand that, we have 4 different connection types in Windows Phone 7 and they are: Wi-Fi, Bluetooth, Cellular and Airplane. Each settings page has different contents based on the connection properties. We will demonstrate these in the next point.

 

Playing with the Code to open Settings page

Now, it’s time for us to write code to open up the settings page of each connection type. How many lines of code do you expect to show the settings page? Remember, we didn’t create any XAML UI for the settings page. So what to do? Don’t worry, we don’t have to create any UI for each page. The API exposes everything for you. Just write 2-3 lines of code and you are done with that. When you call the Show() method, it will open the respective settings page. Let’s have a look into the below points to activate the settings page for each connection type:

 

Airplane Settings


To activate the Airplane settings page, you need to create the instance of the task called “ConnectionSettingsTask” and then assign the ConnectionSettingsType to “AirplaneMode”. This will make sure that the proper settings page open up in the screen, when you call the Show() method of the ConnectionSettingsTask.

Here is the code snippet for you:

WP7 Settings Page - Airplane Mode
   
Bluetooth Settings

To activate the Airplane settings page, you need to create the instance of the task called “ConnectionSettingsTask” and then assign the ConnectionSettingsType to “Bluetooth”. This will make sure that the proper settings page open up in the screen, when you call the Show() method of the ConnectionSettingsTask.

Here is the code snippet for you:

WP7 Settings Page - Bluetooth
   
Cellular Settings

To activate the Airplane settings page, you need to create the instance of the task called “ConnectionSettingsTask” and then assign the ConnectionSettingsType to “Cellular”. This will make sure that the proper settings page open up in the screen, when you call the Show() method of the ConnectionSettingsTask.

Here is the code snippet for you:

WP7 Settings Page - Cellular
   
Wi-Fi Settings

To activate the Airplane settings page, you need to create the instance of the task called “ConnectionSettingsTask” and then assign the ConnectionSettingsType to “WiFi”. This will make sure that the proper settings page open up in the screen, when you call the Show() method of the ConnectionSettingsTask.

Here is the code snippet for you:

WP7 Settings Page - WiFi

 

End Note

Hope this article will be helpful for you to understand the APIs to open up the settings page of each Connection settings task like WiFi, Cellular, Bluetooth and Airplane mode. You will be able to integrate those settings page just using 2-3 lines of code and the complete UI with all the options will be available in the screen.

 

Stay tuned to my blog (http://www.kunal-chowdhury.com) for more articles, tutorials and tips.

I am also available on Twitter @kunal2383 (http://twitter.com/kunal2383).

Like my Blog Page in Facebook (http://www.facebook.com/blog.kunal2383) to be updated.


8 comments

  1. Hi Kunal,

    I am trying your code but i didn't get “ConnectionSettingsTask" class in "Microsoft.Phone.Tasks" namespace. please suggest me what i am missing. I am using the same as you given. what i did, i just add the "Microsoft.Phone.Tasks" namespace and trying to get the class but not able to do. suggest me what i do

    Thanks,
    Rachit

    ReplyDelete
  2. Hello Rachit,

    I think, you don't have the latest SDK installed in your PC. Download the Windows Phone 7.1 SDK Tools (RTW) and install it. Let me know, if you have still any issues.

    ReplyDelete
  3. @Rachit , it coule be because you might not be using the latest SDK as suggested by Kunal or you might be developing an App targetting 7.0 ...

    ReplyDelete
  4. Hi,

    I am looking at making a bluetooth app. However from the documentation I found out that Windows 7 does not expose API to send data from bluetooth . Please let me know if there is any API to send data through bluetooth

    ReplyDelete
  5. Currently no bluetooth APIs are exposed from the WP7 SDK. Hope to see them in future...

    ReplyDelete
  6. Great article about the subject and a good start for a custom WP7 app.

    ReplyDelete
  7. Thanks for the feedback. The said application is already available in the Marketplace. You can get it from: http://www.kunal-chowdhury.com/2012/02/easy-connect-small-wp7-utility.html

    ReplyDelete


 
© 2008-2014 Kunal-Chowdhury.com | Designed by Kunal Chowdhury
Back to top