Windows Phone 7 : Launchers and Choosers
Join the DZone community and get the full member experience.Join For Free
windows phone 7 seems to have captured my attention a lot these days.
so i am ( and will be ) blogging about windows phone 7 like crazy. i
believe that it is microsoft’s first step in the right direction (in the
phone os business). so coming back to windows phone 7 platform.
we all, by now know that all applications in windows phone 7 runs in its own sandbox (execution and file storage, both). and since, we are developing apps for windows phone 7, we will certainly need access to common, phone related functionality, say like sending an email, sms etc. recently, in community tech days pune, in the windows phone 7 app development session by mayur tendulkar , a very cool app was demoed for windows mobile 6.x. this app would send “happy new year” or “happy holidays” message to all the contacts in your phone.
the idea was pretty cool. so for designing this app, we would need access to the phone’s contact list and then, will have to use the phone’s sms api to send out text messages. it is a different ball game here on windows phone 7 platform. windows phone 7 doesn’t give you access to native functionality directly, so microsoft has exposed certain common functionality that you would want to use in your apps in the form of launchers and choosers.
a launcher is an api, that launches built in functionality for the user to accomplish some task and returns nothing back to the calling function in your app. api to make calls, send sms or emails etc are an example of such apis
a chooser on the other hand is an api , that launched a built in functionality for the user to accomplish some task and returns back the data that was chosen by the user to the app. api for choosing contacts, photos etc. come under this category.
important note : your application de-activates (i.e. gets tombstoned), when you trigger a launcher or a chooser. (not sure what tombstoned means, read more about windows phone app life cycle here ).
how to use launchers in your application : launchers are available in microsoft .phone.tasks namespace. make sure to add a using statement for this namespace.
as of now following launchers have been exposed to us (not exactly …):
1. emailcomposetask :
as the name suggests, the emailcomposetask lets you compose emails and send ‘em. you will off course need to setup an email account before you can actually use the email compose functionality. the good news, if no email account has been setup, the shell will ask you to setup an account. ( i guess in the final rtw sdk, this might actually trigger email setup, if not done already)
emailcomposetask emailcomposetask = new emailcomposetask(); emailcomposetask.to = "email@example.com"; emailcomposetask.body = "windows phone rocks!!!" emailcomposetask.cc = "firstname.lastname@example.org"; emailcomposetask.subject = "windows phone"; emailcomposetask.show();
again, quite evident by the name itself. phone call task will let you make a phone call.
phonecalltask phonecalltask = new phonecalltask(); phonecalltask.phonenumber = "180018001800"; phonecalltask.displayname = "steve jobs"; phonecalltask.show();
quite a wrong person to call, i know
3. smscomposetask :
lets you compose an sms
smscomposetask smscomposetask = new smscomposetask(); smscomposetask.to = "1800-180-1800"; smscomposetask.body = "cool phone!!"; <pre>smscomposetask.show();</pre>
4. searchtask :
lets you open the shell search engine
searchtask searchtask = new searchtask(); searchtask.searchquery = "windows phone 7"; searchtask.show();
will trigger the phone’s media player application
mediaplayerlauncher mediaplayerlauncher = new mediaplayerlauncher(); mediaplayerlauncher.media = new uri("vs_logo2010_wmv9_640x360.wmv", urikind.relative); mediaplayerlauncher.show();
the webbrowsertask will let you trigger the phone’s ie mobile browser and redirect the user to the page specified.
webbrowsertask webbrowsertask = new webbrowsertask(); webbrowsertask.url = "http://developer.windowsphone.com"; webbrowsertask.show();
i was not able to find much detail on these launchers. folks reading this block can contribute.:
from the name of it seems, it will launch the phone’s marketplace app and show details. not used this one.
launches the marketplace hub, i guess. i don’t think we will be able to test this on the locked emulator.
i will be posting the next post on using the choosers and will also post the entire solution for your ready reference. once again, thanks for your support and keep looking at this space for more windows phone 7 related posts.
Opinions expressed by DZone contributors are their own.