Click here to Skip to main content
Click here to Skip to main content

How to Call a Number in WP7 using the PhoneCallTask?

By , 12 Apr 2012
Rate this:
Please Sign up or sign in to vote.

Previously we learnt “How to Save a Phone Number in WP7 using the SavePhoneNumberTask?” There we discussed on the basics of the API and details about the implementation stuff with step-by-step details.

Today in this small blog post we will learn how to call a number programmatically in Windows Phone 7 by using the PhoneCallTask API. We will also know what are the limitations of this API class. Continue reading to know further.

Know About the API

Like other phone tasks PhoneCallTask is also a sealed class present inside the Microsoft.Phone.Tasks namespace. It exposes two properties called DisplayName and PhoneNumber of type string. The Show() method shows the phone application where it confirms the user whether to dial or not.

Here is the meta data of PhoneCallTask:

namespace Microsoft.Phone.Tasks
{
    public sealed class PhoneCallTask
    {
        public string DisplayName { get; set; }
        public string PhoneNumber { get; set; }

        [SecuritySafeCritical]
        public void Show();
    }
}

Here is the internal implementation of the Show() method call:

[SecuritySafeCritical]
public void Show()
{
    if (!ChooserHelper.NavigationInProgressGuard((Action) (() => this.Show()))) return;
    ThreadPool.QueueUserWorkItem(new WaitCallback(PhoneCallTask.PhoneDial), (object) this);
}

[SecuritySafeCritical]
private static void PhoneDial(object phoneCallTask)
{
    PhoneCallTask phoneCallTask1 = phoneCallTask as PhoneCallTask;
    string phoneNumber = phoneCallTask1.PhoneNumber;
    string displayName = phoneCallTask1.DisplayName;
    string.IsNullOrEmpty(phoneNumber);
}

I hope that the above internal code will help you to understand the actual implementation of the API which exposes by the SDK for the developers.

Implementation Steps

The implementation steps of PhoneCallTask in your application is really very simple. Just create the instance of the class by populating the properties and call the Show() method as shown in the below code snippet:

var phoneCallTask = new PhoneCallTask
                        {
                            DisplayName = "Kunal Chowdhury",
                            PhoneNumber = "0208795446322"
                        };
phoneCallTask.Show();

The property called “PhoneNumber” is required to dial the number using the PhoneCallTask. You can skip “DisplayName” but “PhoneNumber” is mandatory.

Screenshot 1: How to Call a Number in WP7 using the PhoneCallTask?     Screenshot 2: How to Call a Number in WP7 using the PhoneCallTask?

Limitations

There are some limitations of this class for security purposes. Using PhoneCallTask you can dial any number except any special numbers or service codes, e.g., Balance Check like *111*1#.

To check it out set the PhoneNumber property to any special numbers like: *111*1# and call the Show() method as shown in the below code snippet:

var serviceCallTask = new PhoneCallTask
                          {
                              DisplayName = "Balance Check", 
                              PhoneNumber = "*111*1#" // service call number
                          };
serviceCallTask.Show();

When you run the code, you will notice the below screen if you dial the number from the code:

Screenshot 3: How to Call a Number in WP7 using the PhoneCallTask?

This limitation is made to protect the user from any security hole from any application installed from 3rd party.

I hope that, this post was helpful to you to understand the basic and implementation of the API. If you like these posts, don’t forget to share with your friends, colleagues or others whom you believe that this post will be useful. Don’t forget to share your feedback as it will help me to improve my future posts and also encourage me to deliver more for the benefit of you.

Stay tuned to my blog, Twitter, or Facebook to read more articles, tutorials, news, tips & tricks on various technology fields.

Reference: http://www.kunal-chowdhury.com. You may like to follow me on Twitter @kunal2383 or may like the Facebook page of my blog http://www.facebook.com/blog.kunal2383.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

_ Kunal Chowdhury _
Technical Lead
India India
Kunal Chowdhury is a Microsoft "Client Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik MVP, Nokia Developer Champion, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.
 
He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows 8 (WinRT). He posts his findings, articles in his technical blog and CodeProject.
 
Technical Blog: http://www.kunal-chowdhury.com
Facebook: http://facebook.com/blog.kunal
Twitter : http://twitter.com/kunal2383
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
QuestionFormatting of the code blocks PinmvpMika Wendelius11-Apr-12 18:12 
Formatting of the code blocks seems to be messed up.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 12 Apr 2012
Article Copyright 2012 by _ Kunal Chowdhury _
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid