Today , I’m going to discuss how to use Launchers and Choosers in a Windows Phone 8 application which allows your App to interact with Native WP8 Applications .
What are Launchers ?
We can simply say the Launchers used to run/perform a task beside your App , They are APIs* that allow Apps to do common tasks such as making a phone call, sending an SMS or browsing the web , We will cover the Launchers which is available for you as a developer in your Dev. Platform with a list of the sorts and how we can use it in our App .
* application programming interface (API)
Here you are a list of Launchers which is available in WP Dev. Platform :
Here you are list of launchers with its refrence from MSDN :
- EmailComposeTask launches the Email application which displays a new email message.
- MarketplaceDetailTask launches the Windows Phone Marketplace client application which then shows the details page for a product specified by the unique identifier you provide.
- MarketplaceHubTask launches the Windows Phone Marketplace client application.
- MarketplaceDetailTask launches the Windows Phone Marketplace client application which then displays the review page for your application.
- MarketplaceSearchTask launches the Windows Phone Marketplace client application which then shows the search results based on search terms you provide.
- MediaPlayerLauncher launches the Media Player application and plays the media file you specify.
- PhoneCallTask launches the Phone application and displays the specified phone number and display name. The phone call is not placed until it is initiated by the user.
- SearchTask launches the Search application and performs search query you provide.
- SmsComposeTask launches the Messaging application which displays a new SMS message.
- WebBrowserTask launches the Web browser and displays the URL you provide.
Important Thing !
To have your Launcher works , we need to take a reference from Microsoft.Phone.Taskes , so you have to put this statement in the top of your code file .
using Microsoft.Phone.Tasks;
Using a Launcher
Let’s see a couple of examples for using launchers , I will make a Launcher which make SMS , remember every launcher have their own set of properties and you can dive into it from the msdn reference which i have mentioned above after setting any of them you have to show them by .show()
Our Example :
SmsComposeTask SStoP = new SmsComposeTask(); // we take an object from SmsComposeTask SStoP.To = "010032554860"; // Phone number to send him/her the message SStoP.Body = "Test SMS for this post."; // Our Message SStoP.Show();
What are Choosers ?
Choosers are APIs similar to launchers; however they return a value to the calling application. They are enabling common tasks such as taking a photo or selecting a phone number from the contacts list.
Here you are list of Choosers with its refrence from MSDN :
Using a Chooser
the choosers is slimier to the launcher , they has its own properties , after setting up its properties which you can have from the msdn reference for more info, you need to .Show() them to the user. To do this, you simply call the Show() method on your Chooser.
Important Thing You have to KNOW !
the most important thing for the choosers and the thing which is a difference between launchers and choosers is you have to make an event handler when you are using an chooser for when they make their selection , because will not able to get the values of chooser you set without it , as our example in taking a photo from Phone camera which i showed above in the Figure , which choosers you App gets value of images from the Camera App then have to store it in the App Storage to make the effects on , so we can grab the values they choose .
As an example :
CameraCaptureTask CamTask1 = new CameraCaptureTask(); CamTask1.Completed += new EventHandler<PhotoResult>(CamTask1_Completed); CamTask1.Show(); event handler code:
void CamTask1_Completed(object sender, PhotoResult e) { BitmapImage bmp = new BitmapImage(); bmp.SetSource(e.ChosenPhoto); image1.Source = bmp; } I recommend to use a hardware device for testing App which is using a Chooser because you will have some features disabled in the emulator like make a phone call , sending SMS or capture a Photo from the webcam :) for any thing not clear just leave your comment with your question and I will give you a help .
Hello There. I found your blog using msn. This is a very well written article.
I’ll make sure to bookmark it and return to read more of your useful information. Thanks for the post.
I will definitely return.
Wow, marvelous blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of
your website is excellent, as well as the content!