A blog on novel user interfaces, mobile applications, pervasive and ubiquitous computing. I use the blog as a note pad ;-)

Friday, 18 March 2011

WP7 Tutorial - part 1: Phone calls and SMS

Over the next weeks I like to share some examples I have created while learning to program the Windows Phone 7 platform. The tutorial is mainly explaining some of the APIs and components I found interesting (in particular related to context-awareness and human computer interaction).

If you are really new to programming on this platform the App-Hub is probably a good place to start. There are also plenty of helpful examples on the Microsoft web page. As prerequisite for this tutorial I assume that you have successfully installed Visual Studio (Express), the windows phone development tools, and that you have managed to get your first "Hello World" written, compiled, and deployed. There is also plenty of material on youtube that helps to get started. The Programming Windows Phone 7 book by Charles Petzold (free available as PDF) is also a good starting point.

Several examples that follow in the tutorial (e.g. vibration, accelerometer) having a real phone to test the programs is highly recommended.

The Windows Phone 7 is a phone and hence I start with a program that makes use of the basic phone functionality: making a phone call and sending an SMS.

This example also highlights the approach taken in several of the APIs. Your program (a third party application) is restricted to transfers control to the phones basic functions when making a call or sending an SMS. Basically the API call opens the phone/SMS applications with the parameters you hand over. From a security point of view this is nice as an application can not send SMS or do phone calls without the user recognizing (and agreeing to) it. From a programming perspective this has disadvantages as automation of functionality (e.g. always sent an SMS when I am coming closer than 10 km to home) is not possible.

The example demonstrates how to access interactively the phone book (using the PhoneNumberChooserTask), how to initiate a phone call task (using Microsoft.Phone.Tasks.PhoneCallTask), and how to initiate a SMS task (using Microsoft.Phone.Tasks.SmsComposeTask).The PhoneNumberChooserTask is an example of a callback - used a lot when programming for WP7. The basic concept is to register a function that is called when an event happens. In this case the event is that the number is chosen and then the function myPhoneNumberChooser_Completed is called. The nice thing with Visual Studio is that you do not have to type this (or remember the syntax) - just use the TAB-key after you typed +=

// example how to invoke a phone call and an SMS from a program// the basic approach is that you can set the phone number (and// for SMS the message body) and then you call the phone/sms// application// Albrecht Schmidt, University of Stuttgart// more on how to invoke phone tasks (photo, email, ...)// http://msdn.microsoft.com/en-us/library/ff769543(v=vs.92).aspx