×
Namespaces

Variants
Actions

How to make a Phone call in Windows Phone

From Nokia Developer Wiki
Jump to: navigation, search

This code example shows how to launch the Phone app using PhoneCallTaskAPI in Windows Phone.

Note.pngNote: In contrast to Symbian, Windows Phone does not allow you to make calls "directly" from your own app, or to monitor for and connect to incoming calls. As soon as phone call initiation code below is executed the phone app will be displayed and the user will be asked to confirm that they want to dial the specified number.

WP Metro Icon MobilePhone.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Code ExampleTested with
Devices(s): Nokia Lumia 710,800
CompatibilityArticle
Created: pavan.pareta (16 Nov 2011)
Last edited: vineet.jain (28 Jul 2013)

Introduction

This simple example displays a Phone Call button on the screen. When the button is pressed, the app calls PhoneCallTaskAPI in the Microsoft.Phone.Tasks namespace.

First create a new Windows Phone 7 Silverlight application using the default template in MS Visual Studio. Then add a Button to the XAML as shown below:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Content="Phone Call" Height="82" HorizontalAlignment="Left" Margin="140,234,0,0"
Name="btnCall" VerticalAlignment="Top" Width="auto" Click="btnCall_Click" />
</Grid>

The user interface with the button is shown below:

01.png

Next initialize the PhoneCallTask task object in the constructor of page. To avoid the memory overhead so I initialized in the constructor.

PhoneCallTask phoneTask = null;// Constructor
PhoneNumberChooserTask phoneNumberChooserTask;
 
public MainPage()
{
InitializeComponent();
phoneNumberChooserTask = new PhoneNumberChooserTask();
phoneNumberChooserTask.Completed += new EventHandler<PhoneNumberResult>(phoneNumberChooserTask_Completed);
phoneTask = new PhoneCallTask();
}


The PhoneCallTask class contains two core properties like DisplayName, PhoneNumber and one show() method, which allows us to show the phone application. To make an actual call though the application.

Double-click the button control and click event handler got added to button control object.On the button click event the device's native phonebook is launched & user can then select a contact from it to whom he wishes to make a phone call . See below mentioned code snippet.

private void btnCall_Click(object sender, RoutedEventArgs e)
{
//this will launch the phonebook to choose a contact to call.
phoneNumberChooserTask.Show();
}

As soon as user chooses the contact from phonebook, the following call back method gets called & launches the phone call dialog, asking the user to dial the particular contact or not.

        void phoneNumberChooserTask_Completed(object sender, PhoneNumberResult e)
{
if (e.TaskResult == TaskResult.OK)
{
//Code to start a new phone call using the retrieved phone number.
phoneTask .DisplayName = e.DisplayName;
phoneTask .PhoneNumber = e.PhoneNumber;
phoneTask .Show();
}
}


Following screenshots depict the same :

02.png03.png


Download source code File:WP MakeACall.zip.

Summary

Basically PhoneCallTask API allows to launch the Phone application.

References

This page was last modified on 28 July 2013, at 09:31.
228 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×