Follow us on X (Twitter)  Like us on Facebook  Connect with us on LinkedIn  Subscribe to our YouTube Channel  Subscribe to our WhatsApp Group

Last day we learnt “How to Save 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 the 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.

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.