Phone and SMS - to what extent?
Join the DZone community and get the full member experience.Join For Free
Windows Phone 7 API is known to be pretty restrictive in some cases. This is applied to internal file system access as well as to the type of storage that can be used with the phone. Nonetheless, this is presented to the user under an abstraction layer. The same idea applies to the phone itself (as a calling mechanism) and to the texting application.
If you think about it, the imposed restriction makes sense - you probably don't want some application to dial or text a high-priced (or international) number. Developers might argue, that after all, there is WMAppManifest.xml that allows developers to declare used capabilities and if something is not declared, it cannot be used. As simple as this seems, don't forget that Microsoft doesn't check the source code during the application verification process, therefore it would be hard to check what the application really does unless there would be factual reports of malicious activity.
That being said, the question is - to what extent you can actually use the dialer and SMS? In Microsoft.Phone.Tasks, there are two classes: PhoneCallTask and SmsComposeTask, and here is how those work.
This is the class which can be used to show the dialer with a preset number. You cannot trigger the dialing process, but you can pass a number that a user won't have to dial manually (or write it down somewhere for that reason).
Tip of the day: by following this method you can actually mock calling capabilities on the emulator that otherwise cannot be triggered.
So to start, you need to instantiate the PhoneCallTask class and pass a phone number to it:
PhoneCallTask task = new PhoneCallTask();
task.PhoneNumber = "0000000";
The phone number here is mandatory - if you don't specify one, the dialer dialog won't be displayed. You can also specify a name to be associated with the number.
task.DisplayName = "Some Name";
Before you start dialing, here are some things to remember.
1) You cannot pass service codes, like *37#.
Service codes can only be entered from the phone keypad and not passed by the application. Once again, the reason for this is security.
2) If the phone number passed is 65 (or more) digits long, you will see this error:
3) If the phone number is between 34 and 64 digits long, it will also fail:
Otherwise you should see a call question first:
Notice that the user is not forced to call a number. If he accepts the task, you will see the familiar call interface. You won't be able to use the speaker phone, but you will get the idea behind the call functionality as a whole.
You are even able to add a fake call - the number can be either entered by you or retrieved from the actual emulator phone history:
Notice that although Some Name is not in the phone book, it will be listed as a name rather than a number in the call history. This applies to all calls initiated by your application where there is a DisplayProperty linked to the number.
In fact, there is more stuff you can do here in the emulator - the OS is pretty "locked" but in some cases you can get around things and get to stuff you weren't supposed to get to by default. Here is an example.
Same as with the phone dialer, you cannot force the sending process. But you can passmessage data that is ready to sent, like the phone number and the text message. This is simply done by instantiating the SmsComposerTask class and setting basic properties:
SmsComposeTask task = new SmsComposeTask();
task.To = "000000";
task.Body = "Well hello there!";
You can, of course, send the message to a fake number and you can even attach and store images from sent messages:
You can even get to the Use As Wallpaper part (although at the moment you can't see it). Just click on the attached image and expand the application bar to see the option:
This is pretty much as far as you can go with the existing SDK. We'll see how things eveolve in the next release (or update), but for now you will have to make sure that the application you are working on doesn't rely on automatic calling and texting.
Opinions expressed by DZone contributors are their own.