How to Send SMS Message using SmsComposeTask in a Windows Phone 8 App
SmsComposeTask class is used to send SMS text messages from a Windows Phone 8 app by Windows Phone app developers.
SmsComposeTask (SMS compose task) is one of Windows Phone Launchers and SmsComposeTask is used to launch Messaging app on user's Windows Phone smartphone.
Developers can predefine the SMS text message properties within app code like the body text and the SMS recipient.
Although a Windows Phone developer can set all required properties of the SmsComposeTask, only the phone user has the permission to send the SMS by pressing the send button in Messaging app.
SmsComposeTask Windows Phone Launcher can be used for Windows Phone 7.1 and Windows Phone 8 app development.
To use Windows Launcher SmsComposeTask developers must include Microsoft.Phone.Tasks namespace in their app code.
Here is a sample
' VB.NET code
// C# code
Now programmers can use the SmsComposeTask class in their Windows Phone 8 app to send SMS message from their smartphone.
Let's add a button or an image control on the design surface of your WP8 app page.
In this tutorial, we will use this button or image to trigger an event in code behind of the MainPage.xaml to send SMS text to a recipient.
Send SMS message from Windows Phone 8 app using SmsComposeTask Windows Phone Launcher
You can see above that I used an SMS message image and put it on MainPage.xaml of my recent Windows Phone 8 app development Time Management Quotes app.
Using the Properties of the SMS Image control, switch to Events properties.
Now scrolldown the possible event handlers and create a Tap event for the SMS message.
If you check the code behind page MainPage.xaml.vb of WP8 app page MainPage.xaml, you will see the event handler
In code behind, SMS image Tap event code executes sendSMS method that the app developers can customize according to their requirements.
sendSMS creates an instance of SmsComposeTask Windows Phone Launcher class.
SmsComposeTask instance Body property and To property can be set by code as shown in below VB.NET codes.
For my quotes app, I populate the SmsComposeTask.Body property with the quote text which the user selects in app.
Send SMS message using SmsComposeTask Windows Phone Launcher
Private Sub sms_Tap(sender As Object, e As GestureEventArgs) Handles sms.Tap
Dim quote As Quote = TimeTrackingQuotes.Read(currentQuoteNo)
If Not quote Is Nothing Then
Private Sub sendSMS(quote As Quote)
Dim smsComposeTask As SmsComposeTask = New SmsComposeTask()
'smsComposeTask.To = ""
smsComposeTask.Body = quote.QuoteText
When the Show() method of the SmsComposeTask class instance is executed, the default Messaging app on the users Windows Phone 8 device launched and display SMS message with configured values ready to be send.
The Windows Phone user can change the SMS message and choose the recipients of the text message by using the Messaging app.
Only when he/she presses Send button the message will be send.
Compose and send SMS message from Windows Phone 8 app using SmsComposeTask Windows Phone Launcher
Programmers can use other Windows Phone Launchers WebBrowserTask, EmailComposeTask and ShareLinkTask in their Windows Phone 8 app development codes to provide additional communication functionalities in their apps.