Send text message from Windows Phone

This question was asked to me by a student developer from India who explained that he had just started developing and was looking to make his first app for the Windows Phone platform.

To answer the question quickly, yes it is possible to send a text message from your Windows Phone application. In this tutorial, I will show you the most simple way of sending a text message utilizing the built-in Messaging system of the Windows Phone OS. There are also other methods of sending text messages with a Windows Phone app without leaving the app itself and I will give an overview of those at the end. I will also look at how you can add the same behavior in a Windows Phone RT app.

Windows Phone 8 / 8.1 Silverlight implementation


private void Button_Click(object sender, RoutedEventArgs e)
{
    var composer = new SmsComposeTask();
    composer.To = "mobile-telephone-number";
    composer.Body = "This is a text message from an app!";
    composer.Show();
}

The implementation takes advantage of launchers that are provided by the Windows Phone OS in the Microsoft.Phone.Tasks namespace which give developers access to core functionality.

Windows Phone 8.1 RT (Universal App)


async private void Button_Click(object sender, RoutedEventArgs e)
{
    var message = new ChatMessage();
    message.Recipients.Add("mobile-telephone-number");
    message.Body = "This is a text message from an app!";
    await ChatMessageManager.ShowComposeSmsMessageAsync(message);
}

Using the Windows.ApplicationModel.Chat namespace, you can take advantage of the same functionality as the Silverlight application in your Windows Phone RT Universal App.

Alternatives

While utilizing the phone’s core functionality may be a great choice, there are also other alternatives available for sending text messages through a Windows Phone application using external services. One such service is Twilio.

Twilio provides a text messaging API that enables users to communicate with apps and chat to one another. A great feature of Twilio is that it lets you develop using your favorite programming language whether it be for the web, mobile device or desktop application. The best part is that the service is hosted in the cloud! So all you need to do is ping off your text message to Twilio and it handles the rest for you.

There are also other great alternatives available so check those out and I hope that this tutorial helps out many others!

Join the discussion 2 Comments

Leave a Reply