Previously, we learnt “How to Save a Phone Number in WP7 using the SavePhoneNumberTask?”. There, we discussed 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 the limitations are 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.
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#"
};
serviceCallTask.Show();
When you run the code, you will notice the below screen if you dial the number from the code:
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 basics and implementation of the API. If you like these posts, don’t forget to share with your friends, colleagues or others for whom you believe 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.