SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Windows Phone Application Development Tutorials, Articles and Resources for Mobile App Programmers


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

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
Imports Microsoft.Phone.Tasks
// C# code
using Microsoft.Phone.Tasks;
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
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
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
  sendSMS(quote)
 End If
End Sub

Private Sub sendSMS(quote As Quote)

 Dim smsComposeTask As SmsComposeTask = New SmsComposeTask()

 'smsComposeTask.To = ""
 smsComposeTask.Body = quote.QuoteText
 smsComposeTask.Show()

End Sub
Code

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.

use SmsComposeTask Windows Phone Launcher to send SMS message  Windows Phone Messaging app to send SMS text
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.



Windows 10 Games

Microsoft Games on Windows 8 and Windows 10


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.