We have previously introduced how to obtain contact information by using APIs provided by Windows Phone SDK 7.1. However, there is no direct API for adding contacts. We can only use the selector (Choosers) to add contact information.
SaveContactTask provides methods and events for starting the Contact application and enabling the user to save the contact. An example of code writing is as follows.
1. Create a selector and add the selector operation completion event (Completed)
SaveContactTask saveContact = new SaveContactTask ();
SaveContact. Completed + = new EventHandler <SaveContactResult> (saveCompleted );
2. assign values to the selector (contact information) and call the selector
SaveContact. FirstName = "Yu zhile ";
SaveContact. MobilePhone = "13888888888 ";
SaveContact. HomeAddressStreet = "Nanjing City, Jiangsu Province ";
SaveContact. PersonalEmail = "huizhang212@163.com ";
SaveContact. Show ();
3. selector operation completion event
Void saveCompleted (object sender, SaveContactResult e)
{
Switch (e. TaskResult)
{
Case TaskResult. OK:
MessageBox. Show ("the contact is saved successfully! ");
Break;
Case TaskResult. Cancel:
MessageBox. Show ("the user canceled the operation! ");
Break;
Case TaskResult. None:
MessageBox. Show ("the contact is not saved! ");
Break;
}
}
Currently, you can only query and add Contacts. You cannot modify or delete contacts. Only one user can manually process it through the system.