In this short tutorial we are going to see how to use a SMS Compose task to compose a Short Message and send it using the Short Messaging Services available over the network. SMS compose task first launches the Messaging application with the New Message window, we can play around with assigning the receipt by default or provide the option to the end user to select the recipient from the contacts. Also we can provide the option for the end user to have a static message which can be passed from the application which we are developing or also we can specify a custom message for each and every user. Let us see the steps on how to achieve this task from the application development in Windows Phone 7. [more]
Open Visual Studio 2010 IDE and create a new Silverlight for Windows Phone project with a valid project name as shown in the screen below. Once the project is created add some controls which are used to trigger the SMS Compose task.
Now drag and drop few controls to the screen which is used to trigger event which triggers the SMS Compose task to get the user inputs. Once we designed the screen with the controls we can see the screen looks like below.
Now we need to write our code in the button click event to trigger the SMS Compose task on the user click. To do that just go to the code behind and first add the USING handler code on top with the existing using statements as shown in the code below.
Next is to add the below code to the button click event which basically creates an instance of the SMS Compose task which shows the New SMS Compose Message Application as shown in the code below.
public partial class MainPage : PhoneApplicationPage
private void button1_Click(object sender, RoutedEventArgs e)
SmsComposeTask smsCom = new SmsComposeTask();
smsCom.To = txtTo.Text.ToString();
smsCom.Body = txtBody.Text.ToString();
Now we are done with our code, just run the application by pressing F5 directly from the keyboard or we can use the Build and execute the project option from the tool bar to run the application. Once the Build is successful we can see the Windows Phone emulator with the application and the expected outputs as shown in the screens below.
So in this article we have seen how to use the SMS Compose task to compose and send an SMS. We need to note that unless and until the user clicks on the Send button the SMS is not sent but the composing can be done as a static message or also we can create a dynamic message and send it across. That’s it from this short tutorial on Windows Phone see you all in the next tutorial soon. Mean while Happy Programming!!!