Windows Phone 7

Code to Send SMS in Windows Phone 7

Launchers are used to perform task provided by phone operating system. Sending SMS is feature of Windows phone operating system and can be used by Launcher API. SmsCompseTask launcher is used to send SMS. This task class is defined as below,

image

To work with SmsComposeTask, first you need to add namespace of Microsoft.Phone.Task

clip_image001

Then create instance of SmsComposeTask.

clip_image003

Next you need to set required or optional parameter for the launcher task. Required parameters for SmsComposeTask are

  1. To number
  2. Body of SMS

 

So first set the parameter as below,

clip_image001[6]

And SMS body as below,

clip_image002

Last step you need to launch SMS send application provided by operating system. You can show that as below,

clip_image003

If you put all code together and want to send SMS on click event of button then full code will be as below,


using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace test
{
public partial class MainPage : PhoneApplicationPage
{

public MainPage()
{
InitializeComponent();
}

private void btnSendSMS_Click(object sender, RoutedEventArgs e)
{

SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = "9158153792";
smsComposeTask.Body = "hey I am sending u SMS";
smsComposeTask.Show();

}
}
}

 

When you run above code you will get application running as below,

image

When you click on Send SMS button, you will get drafted SMS with TO and body set as below,

image

Now you can either edit the message or set other recipients or send SMS as it is. I hope this post was useful. Thanks for reading Smile

If you find my posts useful you may like to follow me on twitter http://twitter.com/debug_mode or may like Facebook page of my blog http://www.facebook.com/DebugMode.Net If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.

About Dhananjay Kumar

Dhananjay Kumar is Developer, Blogger , Speaker, Learner , Mindcracker & Microsoft MVP.

Discussion

Trackbacks/Pingbacks

  1. Pingback: Code to Send SMS in Windows Phone 7 - October 18, 2011

  2. Pingback: Dew Drop – October 18, 2011 | Alvin Ashcraft's Morning Dew - October 18, 2011

  3. Pingback: Monthly Report October 2011: Total Posts 31 « debug mode…… - November 1, 2011

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,380 other followers

Tweets

Categories

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my current or previous employer's view in anyway. © Copyright 2012