Launchers in Windows Phone

Introduction

Every Smartphone has some features which are defined by OS manufacturer. OS manufacturer provide these features for programmer’s ease, so you can use it externally in your App. From different point you can assume that, OS manufacturer restricts programmer to alter their predefined service/code.

Every Smartphone OS has these features with their different names. Though, we are focusing on Windows phone.

And, in Windows phone we call it Launcher and Chooser.

Launchers

One of the basic differences between two is,

Launcher will launch Windows Phone Service instantly and without returning any value. Whereas, Chooser will launch Windows phone Services and it will return some value back to the code.

SMS Compose Service is a type of Launcher where you can send SMS to the specified number. It’s not the responsibility of code to get back the returned data from the Launcher. So, SMS Sending has completed or not is handled by itself Launcher.

Where, Chooser will detect the returned data and can be handled latter. For instance, you are choosing a contact from Contact Chooser, and the chooser will return the selected contact back to the code.

In short, Choosers are those services from which we are getting something in return but in launcher we will launch the Service only without any expectation to get any value in return.

For now, it is enough but we will elaborate different kinds of Launcher and Chooser latter in this article.

First, we go for Launchers:

Before adding any Launcher Task, you make sure that you have a Microsoft.Phone.Tasks namespace in your project.

There is a common way to handle all the Launcher in Windows phone.

Just follow these simple steps,

Step 1: Create the Object of desired Launcher.
Step 2: Assign the value to predefined Object’s field or call the methods. (Use Intelisense always ;))
Step 3: Call the Show() method to launch the Launcher.

Following are the Launchers used in Windows Phone :

EmailComposeTask : Launch the Compose-Email Task.

So, we have a Button where we implement the EmailComposeLauncher,

private void button1_Click(object sender, RoutedEventArgs e)

{
    EmailComposeTask compose = new EmailComposeTask(); // Creation of Object 
    compose.To = "[email protected]"; // Assigning the Value for 'TO' field
    compose.Subject = "C# Corner Windows Phone Tutorial"; //Assiginig 'SUBJECT' Value
    compose.Body = "Hello I 'm testing my New Launcher App Tutorial"; //Assigning 'BODY' value
    compose.Show(); //At last, we call the Show() method to Launch
}

WebBrowserTask : Launch the Default Web Browser to open the specified URL.

private void button2_Click(object sender, RoutedEventArgs e)

{
    WebBrowserTask web = new WebBrowserTask(); // Creation of WebBrowser's Object

    web.Uri = new Uri("http://google.com", UriKind.RelativeOrAbsolute); // uri fields accepts URI type only

    web.Show(); // ultimately, we call the Show() method

}

SmsComposeTask : Launch the SMS Composer of your Windows phone.

private void button3_Click(object sender, RoutedEventArgs e)

{
        SmsComposeTask sms = new SmsComposeTask(); // Creation of Object
        sms.To = "9933495533"; // Assign the 'To' and 'Body' field
        sms.Body = "Hello C# Corner";

        sms.Show(); //Call the Show() method to Launch

}

PhoneCallTask : Launch the Phone Dialer. Or, You can call someone using code.

private void button4_Click(object sender, RoutedEventArgs e)

{
    PhoneCallTask phone = new PhoneCallTask(); // Creation oF Object
    phone.DisplayName = "Admin"; //Assign the Fields
    phone.PhoneNumber = "9933000000";

    phone.Show(); //Call Show() method

 }

MarketplaceReviewTask : Launch the Review window of your App in Marketplace. RATE ME section of any App uses following code

private void button5_Click(object sender, RoutedEventArgs e)

{
    MarketplaceReviewTask market = new MarketplaceReviewTask();
    market.Show(); //Just Call The Show() method
}

Similarly, you can try MarketplaceHubTask, MarketplaceDetailsTask, MarketplaceSearchTask.

BingMapTask : Launch the Bing Map and map your Search term. There is one more Task called BingMapDirectionTask.

private void button6_Click(object sender, RoutedEventArgs e)

{
        BingMapsTask bing = new BingMapsTask();

        bing.SearchTerm = "India";

        bing.Show();

}

MediaPlayerLauncher : Launch the default Media Player to open the remote media file. i.e Play your Media file in your Media Launcher.

private void button7_Click(object sender, RoutedEventArgs e)
{

    MediaPlayerLauncher media = new MediaPlayerLauncher();

    media.Media = new Uri("http://songs.djmazadownload.com/music/320/indian_movies/Dhoom%203%20%282013%29/04%20-%20Dhoom%203%20-%20Dhoom%20Machale%20Dhoom%20%5BDJMaza.Info%5D.mp3", UriKind.RelativeOrAbsolute);

    media.Show();

}

SearchTask : launch the BING search engine to search your specified tearm. i.e Search your text in Bing Search Engine.

SearchTask search = new SearchTask();

private void button8_Click(object sender, RoutedEventArgs e)
{

    search.SearchQuery = "C# Corner";
    search.Show();

}

Conclusion

We have covered almost all the Launcher under Windows Phone. Since, these are easy part to implement. For further reference you can go to windows phone


Similar Articles