Over a million developers have joined DZone.

8 Common Windows Phone Tasks in Mango

· Mobile Zone

Learn how to Deliver Better Mobile Apps Faster with Continuous Quality by managing the complexities of testing multiple devices and scenarios with this whitepaper from Perfecto Mobile.

In this blog post I will have a closer look at different Phone Tasks and their uses. All those tasks can be found in the Microsoft.Phone.Tasks namespace.

Each Task class has a method called "Show()" which is responsible for executing the task.

For the AddressChooserTask I created a new project with a button and a click event. In the click event handler I add the following:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        AddressChooserTask addressChooserTask = new AddressChooserTask(); addressChooserTask.Show();
    }

Running the application gives me that result:

1       2

When I click my button the application shows me a list of my contacts.

Let’s have a look at another task, the CameraCaptureTask: Same application, just a different button and a different click event:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        CameraCaptureTask cameraCaptureTask = new CameraCaptureTask(); cameraCaptureTask.Show();
    }

Obviously testing the CameraCaptureTask on the emulator is not as satisfying as testing it on a real device. Running it in the emulator will show a moving box across the screen edges. To take the snap simply click the Capture button:

1       2       3

Now I am going to look at the EmailAddressChooserTask:

    Code Snippet
    private void Button_Click(object sender, RoutedEventArgs e)
    {
    EmailAddressChooserTask emailAddressChooserTask = new EmailAddressChooserTask(); emailAddressChooserTask.Show();
    }

Running this looks quite similar to the AddressChooserTask:

1       2

So far no rocket science. Now let’s take a look at the EmailComposeTask. This task will create the email composer UI. You can set different options like ‘To’, ‘CC’, ‘BCC’, Subject or Body of the email. The code in the click event handler looks like this:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        EmailComposeTask emailComposeTask = new EmailComposeTask();
        emailComposeTask.To = "user@email.com";
        emailComposeTask.Subject = "Test Email";
        emailComposeTask.Body = "This is a test message demonstrate EmailComposeTask.";
        emailComposeTask.Show();  
    }

Of course the emulator itself does not have an email box, so the result I get when running this looks like this:

1       2

The PhoneCallTask:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        PhoneCallTask phoneCallTask = new PhoneCallTask();
        phoneCallTask.DisplayName = "Andrea Haubner";
        phoneCallTask.PhoneNumber = "123456789";
        phoneCallTask.Show();
    }

1       2

Of course you can also just pick a number with the PhoneNumberChooserTask:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        PhoneNumberChooserTask phoneNumberChooserTask = new PhoneNumberChooserTask();
        phoneNumberChooserTask.Show();
    }

1       2

The next task I am showing is the PhotoChooserTask:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        PhotoChooserTask photoChooserTask = new PhotoChooserTask();
        photoChooserTask.ShowCamera = true;
        photoChooserTask.Show();
    }

Running in the emulator gives this result:

1       2       3

 

Let’s have a look at the SearchTask:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        SearchTask searchTask = new SearchTask();
        searchTask.SearchQuery = "Andrea Haubner";
        searchTask.Show();
    }

1       2

 

The last task I want to look at is the WebBrowserTask:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        WebBrowserTask webBrowserTask = new WebBrowserTask();
        webBrowserTask.Uri = new Uri("http://www.andreahaubner.blog.com", UriKind.Absolute);
        webBrowserTask.Show();
    }

This will launch the browser with the mentioned URL:

1       2

 

For this blog post I just randomly picked some Tasks that I think are the most used ones.

Here you can find an overview of all tasks that are available.

 

To be continued…


Source:  http://andreahaubner.blog.com/2011/11/21/phone-tasks-in-mango/

Do you know Why Apps Succeed? Perfecto Mobile analyzed over 1,000 responses to their Digial Quality Strategies survey and aim to answer the question, "Why do apps succeed?" in this exclusive report.

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}