In this article you will see how to add a new contact, make a call and send SMS to it in Windows Phone 7.IntroductionIn 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.A 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 ContactCreate an instance of SaveContactTask
SaveContactTask newContact = new SaveContactTask();
Declare the Completed event of this instance to show a message if the 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!"); }}The newContact.Show method launches the contacts application. Tap on the save icon to save it to the phone contact list. A message, "Contact added!" is displayed when the contact is saved else it shows a "Contact not added!" message.Making a CallPhoneCallTask is used to make a callprivate void btnCall_Click(object sender, RoutedEventArgs e){ PhoneCallTask phoneCaller = new PhoneCallTask(); phoneCaller.PhoneNumber = "99********"; phoneCaller.DisplayName = "dpkshr"; phoneCaller.Show();}Here, the Show method launches the phone application that takes your permission to make the call. Tap on the call button to call or the don't call button to cancel. Sending SMSSMSComposeTask is used to send SMSprivate void btnSendSMS_Click(object sender, RoutedEventArgs e){ SmsComposeTask smsSender = new SmsComposeTask(); smsSender.To = "99********"; smsSender.Body = "Hey How are you!"; smsSender.Show();}The Show method launches a composed message with the sender and body we have given. You need to click on the send icon to send the SMS.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: