In last two blog posts we learnt how to save email address in WP7 and how to send email. We also learnt the internal implementation of the APIs used by the Windows Phone 7 SDK.

Today in this blog post we will explore how to retrieve email address from contact list with a simple example (including the internal implementation of the API). Don’t forget to provide your feedback. If you have any queries, let me know. I will try to answer you as early as I can.

Related Posts

How to Retrieve Email Address in WP7 using the EmailAddressChooserTask?

Know About the API

EmailAddressChooserTask is a sealed class present in the Microsoft.Phone.Tasks namespace and derives from ChooserBase of type EmailResult. It contains only a single method named Show() when called opens the Email Chooser UI in the screen.

It allows an application to launch the Contacts application. Use this to obtain the email address of a contact selected by the user.

Here is the meta data of the EmailAddressChooserTask class:

namespace Microsoft.Phone.Tasks

{

publicsealedclass EmailAddressChooserTask : ChooserBase<EmailResult>

{

publicoverridevoid Show();

}

}

If we explore the decompiled version of the class, we will see the actual implementation of the SDK API. Here is the original implementation of the class:

Once you go thru the decompiled version of the class from the above code snippet, you will understand the code implementation easily.

Implementation Steps

To integrate this in your application, first of all you need to create the instance of the EmailAddressChooserTask and register for the Completed event (if you want to handle the task result). Call the Show() method to launch the chooser screen.

Here is the completed event, where you can handle the result easily. The “EmailResult” returns the contact display name and email address. Based on the TaskResult, take care of user interaction.

void EmailAddressChooserTaskCompleted(object sender, EmailResult e)

{

switch (e.TaskResult)

{

case TaskResult.OK:

// On Success

MessageBox.Show(e.DisplayName + ": " + e.Email);

break;

case TaskResult.Cancel:

// Interrupted by the user

break;

default:

break;

}

}

Here is the screenshot of what you will actually see once you run the above code. When you call the Show() method, this will popup the contact list. When you click on the contact, it will come to the completed event and as per our implementation, it will show the name and email address of the specified contact.

I hope that this post was very useful for you to understand the SDK API, it’s internal code implementation and the sample code implementation. Please leave your feedback below to leave your comment.

Stay tuned to my blog, twitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

About Me

Kunal Chowdhury is a Windows Platform Development MVP of Microsoft, a Telerik MVP, Nokia Developer Champion, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.