Blograby

Contacts and Messaging

Mobile computing is typically an activity based around contacts and messaging. All Windows Phone 7 devices support a contacts list, standard phone capability, SMS (text) messaging, and email. An application can integrate with these features
to make it easier for users to add specific contacts to their contacts list, make a phone call, send pre-populated SMS messages, and send pre-populated emails to their contacts. All of these features display screens where the user must manually confirm the action. For security reasons, your code cannot perform any of these tasks in the background without the user being aware.

The contacts and messaging functionality is managed by the operating system, but your applications can invoke the appropriate task launcher or chooser to initiate it. For example, you can prompt the user to call to a specific phone number
using the PhoneCallTask launcher. The user can click the call button to initiate the call or click the don’t call button to cancel the operation and close the launcher.

The following task launchers and choosers are available for contacts and messaging:

To use these task launchers and choosers, you must do the following:

Some of the task launchers and choosers accept a reference to a callback that is executed when it completes. For example, the EmailAddressChooserTask passes the chosen email address to the callback inside an instance of the EmailResult arguments class. All the callbacks receive a task-specific arguments type, and all of these include
a TaskResult property that indicates if the task was completed successfully or cancelled by the user.

The following code example shows the simple case where the task does not provide callback functionality. It invokes the phone dialing feature with a specified phone number displayed. The user dials the number by clicking the call button.

C#
PhoneCallTask phoneTask = new PhoneCallTask();
phoneTask.DisplayName = “Tailspin Support”;
phoneTask.PhoneNumber = “5551234567”;
phoneTask.Show();

For some tasks that do accept a callback, such as the Save EmailAddressTask and SavePhoneNumberTask, you may not be interested in whether the user actually did add the suggested contact to their contacts list. In this case, you simply omit setting the callback for the task. The following code example shows how you can prompt a user to add a specific email address (with a display name) to the contacts list.

C#
SaveEmailAddressTask saveEmaiTask = new SaveEmailAddressTask();
saveEmaiTask.Email = “Tailspin <customerservice@tailspin.com>”;
saveEmaiTask.Show();

For tasks where you do specify a callback, you access the result though the event argument passed to the callback handler. For example, the following code invokes the chooser for an email address and specifies a callback named EmailChooser_Completed.

C#
EmailAddressChooserTask emailAddressTask =
new EmailAddressChooserTask();
emailAddressTask.Completed
+= new EventHandler<EmailResult>(EmailChooser_Completed);
emailAddressTask.Show();

The callback can check if the user selected an email address. If so, it invokes the email editor with a pre-populated email ready for the user to edit and send.

C#
void EmailChooser_Completed(object sender, EmailResult result)
{
if (result.TaskResult == TaskResult.OK)
{
EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.To = result.Email;
emailComposeTask.Subject = “My Message Subject”;
emailComposeTask.Body = “This is the content of my message”;
emailComposeTask.Show();
}
}

For more information about the tasks described in this section, and the other types of tasks available on Windows Phone 7 devices, see “Microsoft.Phone.Tasks Namespace” on MSDN (http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks(VS.92).aspx).

 

Exit mobile version