programming4us
programming4us
MOBILE

Integrating Applications with the Windows Phone OS : Working with Launchers and Choosers

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
In this section, you will explore how to work with launchers and choosers from within your application. You will use PhoneNumberChooserTask and SmsComposeTask to create an application that selects a contact from the shared list of contacts on the phone and then composes a text message to that contact's phone.

1. Creating the User Interface

The user interface for this sample consists of a single button; when the user clicks this button, a list of contacts will be displayed, allowing the user to pick one.

  1. Launch Visual Studio 2010 Express, and select the Windows Phone Application template. Change the project name to "Tasks," select OK, and Visual Studio will set up a new project.

  2. Open MainPage.xaml in design mode, and add a button to the page. Change the button's caption to be "Send SMS."

2. Coding Application Logic

When the user clicks the "Send SMS" button of your application, she should be presented with a list of contacts available on your device. Conveniently for us, even on the emulator, Microsoft has included a sample list of contacts for us to test an application with.

  1. Open MainPage.xaml.cs (right-click MainPage.xaml and select View Code). At the top of the page, add the following using statement:

    using Microsoft.Phone.Tasks;

  2. Declare the following module-level variable for the PhoneNumberChooserTask chooser (insert it right above the MainPage() constructor):

    private PhoneNumberChooserTask _choosePhoneNumberTask;

  3. Instantiate a new PhoneNumberChooserTask object within the MainPage() constructor, and associate a method to invoke when the user selects a contact from the list. The method to call upon the chooser's return will accept the phone number selected as one of the parameters. Use the following two lines of code to accomplish that:

    _choosePhoneNumberTask = new PhoneNumberChooserTask();
    _choosePhoneNumberTask.Completed += new
    EventHandler<PhoneNumberResult>(ChoosePhoneNumberTaskCompleted);

  4. Code the ChoosePhoneNumberTaskCompleted method that will be invoked upon selection of a contact from the list. Note the use of an SmsComposeTask launcher to create a new text message to the person you have selected from the contact list:

    private void ChoosePhoneNumberTaskCompleted(object sender, PhoneNumberResult e)
    {
    new SmsComposeTask() { Body = "SMS using Windows Phone 7 Chooser", To =
    e.PhoneNumber }.Show();
    }


  5. Finally, add code to react to the button-click event by opening the PhoneNumberChooser launcher. The easiest way to accomplish this is to double-click the button with MainPage.xaml open in design view and make the button-click event look like the following:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
    _choosePhoneNumberTask.Show();
    }

  6. Press F5 to run your application. Click the Send SMS button, and select Andrew R. (Andy) Hill from the list of contacts that comes up on the emulator. Immediately after selecting Andy, you should see a screen similar to Figure 1, where the SMS message has been composed and is ready to be sent to Andrew.

To summarize what you have learned so far, your application integrates with the Windows Phone OS via a set of API methods referred to as launchers and choosers. Working with launchers and choosers is fairly straightforward, as illustrated by the foregoing example.

One major limitation of mobile platforms is their inherently short battery life. This limitation causes OS designers and phone manufacturers to come up with various techniques to balance short battery life with positive user experience. One such technique is to allow only one application to run on the phone at any given time. You may be wondering then, what happens when your application yields execution to the built-in Windows Phone OS application invoked with the launcher? That brings us to the important Windows Phone concept of application tombstoning, a subject you'll explore along with the Windows Phoneapplication life cycle in the next section.

Figure 1. SMS is composed and ready to go to Andrew.

Other  
  •  Introducing Windows Phone 7 Launchers and Choosers
  •  Java Mobile Edition Security : Development and Security Testing (part 3) - Code Security & Application Packaging and Distribution
  •  Java Mobile Edition Security : Development and Security Testing (part 2) - Reverse Engineering and Debugging
  •  Java Mobile Edition Security : Development and Security Testing (part 1) - Configuring a Development Environment and Installing New Platforms & Emulator
  •  Java Mobile Edition Security : Configurations, Profiles, and JSRs
  •  Programming the Mobile Web : Performance Optimization
  •  Programming the Mobile Web : Testing and Debugging (part 3) - Client-Side Debugging
  •  Programming the Mobile Web : Testing and Debugging (part 2) - Server-Side Debugging & Markup Debugging
  •  Programming the Mobile Web : Testing and Debugging (part 1) - Remote Labs
  •  Windows Phone 7 : Working with Controls and Themes - Adding Transition Effects
  •  
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    programming4us programming4us
    Celebrity Style, Fashion Trends, Beauty and Makeup Tips.
    programming4us
     
     
    programming4us