EziData Solutions

Web, NET and SQL Server

Sending an SMS from Window Phone 7 App

In a previous post I covered how to send emails to one of your contacts directly from a Windows Phone 7 application. WP7 enables you to support a number of other communication channels, including SMS, right inside your application.

private void Button_Click(object sender, RoutedEventArgs e)

{

    SmsComposeTask sms = new SmsComposeTask();

    sms.To = "555 1234";

    sms.Body = "Wow sending an sms from WP7 is so easy";

    sms.Show();

}

 

While it is possible to send an SMS message directly to a mobile number (as shown in the code above), it would normally be preferable to allow the user to select one of their contacts before sending the message.

private void Button_Click(object sender, RoutedEventArgs e)

{

    PhoneNumberChooserTask phone = new PhoneNumberChooserTask();

    phone.Completed += new EventHandler<PhoneNumberResult>(phone_Completed);

    phone.Show();

}

 

void phone_Completed(object sender, PhoneNumberResult e)

{

    //only continue if the user selected a contact

    if (e.TaskResult == TaskResult.OK)

    {

        SmsComposeTask sms = new SmsComposeTask();

        sms.To = e.PhoneNumber;

        sms.Body = "Wow sending an sms from WP7 is so easy";

        sms.Show();

    }

}

 

The SMSComposeTask launches the messaging application on the OS and displays the new message. As with all the other Launcher tasks we have investigated, the user has the option to edit the message or even cancel sending it altogether.

Posted: Apr 15 2011, 05:57 by CameronM | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Windows Phone 7 | WP7