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

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

SaveContactTask newContact=new SaveContactTask();

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

newContact.Completed+= new EventHandler<SaveContactResult>(newContact_Completed);

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

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!");
     }
}

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

private void btnCall_Click(object sender, RoutedEventArgs e)
{
     PhoneCallTask phoneCaller = new PhoneCallTask();
     phoneCaller.PhoneNumber = "99********";
     phoneCaller.DisplayName = "dpkshr";
     phoneCaller.Show();
}

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

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

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

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

Leave a Reply

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