How to add a new Contact, make a call and send SMS to it in Windows Phone 7

By | February 13, 2012

In this article you will see how to add a new contact, make a call and send SMS to it in Windows Phone 7

Introduction

In this article we will use different Tasks provided by Windows Phone 7 to add a new contact to the phone contact list, make a call and send SMS to that contact.

Task is used to get information about a module from the phone. To use a Task, you need to add Microsoft.Phone.Tasks namespace.

Adding New Contact

Create an instance of SaveContactTask

[sourcecode language=”csharp”]
SaveContactTask newContact=new SaveContactTask();
[/sourcecode]

Declare Completed event of this instance to show message if contact has been added

[sourcecode language=”csharp”]
newContact.Completed+= new EventHandler<SaveContactResult>(newContact_Completed);
[/sourcecode]

Provide values to the SaveContactTask instance you want to save to the new contact. Show is called here to launch the contact application with the values you given

[sourcecode language=”csharp”]
private void btnSaveEmail_Click(object sender, RoutedEventArgs e)
{
newContact.FirstName = "Deepak";
newContact.LastName = "Sharma";
newContact.MobilePhone = "99********";
newContact.Show();
}

void  newContact_Completed(object sender, SaveContactResult e)
{
if(e.TaskResult== TaskResult.OK)
{
MessageBox.Show("Contact added!");
}
else
{
MessageBox.Show("Contact not added!");
}
}
[/sourcecode]

Here, newContact.Show method launches the contacts application. Tap on save icon to save it to the phone contact list. A message, “Contact added!” is displayed when contact is saved else it shows “Contact not added!” message.

 

Making a Call

PhoneCallTask is used to make a call

[sourcecode language=”csharp”]
private void btnCall_Click(object sender, RoutedEventArgs e)
{
PhoneCallTask phoneCaller = new PhoneCallTask();
phoneCaller.PhoneNumber = "99********";
phoneCaller.DisplayName = "dpkshr";
phoneCaller.Show();
}
[/sourcecode]

Here, Show method launches the phone application that takes your permission to make the call. Tap on call button to call or don’t call button to cancel.

 

Sending SMS

SMSComposeTask is used to send SMS

[sourcecode language=”csharp”]</pre>
private void btnSendSMS_Click(object sender, RoutedEventArgs e)
{
SmsComposeTask smsSender = new SmsComposeTask();
smsSender.To = "99********";
smsSender.Body = "Hey How are you!";
smsSender.Show();
}
[/sourcecode]

Show method launches composed message with the sender and body we have given. You need to click on send icon to send the SMS.

0 thoughts on “How to add a new Contact, make a call and send SMS to it in Windows Phone 7

  1. Goji Xtreme

    Hi, I would like to subscribe for this website to obtain most recent
    updates, so where can i do it please help out.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *