Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

如何在Windows Phone 7上发送短信

From Wiki
Jump to: navigation, search
WP Metro Icon Messages.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata

最后由 hamishwillee 在 17 Jul 2013 编辑

这篇文章展示了如何在Windows Phone 应用程序中发送短信。


这篇文章描述了如何在Windows Phone 应用程序中发送短信。短信的发送是利用SmsComposeTask API来完成的。要发送短信,请打开本地短信编辑器为用户提供一个选项,用来发送短信或放弃它。


现在来讨论短信发送,让我们创建一个简单的windows phone应用程序,在the Visual Studio 2010中选择File->NewProject->Windows Phone Application。在应用程序的MainPage.xaml文件中添加一个文本Label(显示进入短信信息),TextBpx(输入短信内容)和一个Button(点击它,短信编辑器打开),如下所示:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBox Height="92" HorizontalAlignment="Left" Margin="56,121,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="289" />
<TextBlock Height="52" HorizontalAlignment="Left" Margin="26,51,0,0" Name="textBlock1" Text="Please enter text for sms:" VerticalAlignment="Top" Width="256" />
<Button Content="Send SMS" Height="86" HorizontalAlignment="Left" Margin="96,276,0,0" Name="button1" VerticalAlignment="Top" Width="198" Click="button1_Click" />




using Microsoft.Phone.Tasks;
namespace SmsSender
// function which gets called when 'Send SMS' button is clicked
string ismsboby;
private void button1_Click(object sender, RoutedEventArgs e)
ismsboby = textBox1.Text; // Fetch the text from textbox created in XAML
SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = "9012345566778"; // Mention here the phone number to whom the sms is to be sent
smsComposeTask.Body = ismsboby; // the string containing the sms body
smsComposeTask.Show(); // this will invoke the native sms edtior

只要“Send SMS”按钮被点击,就会打开本地SMS应用程序,短信内容和电话号码将通过上面的代码进行填充。



Sentsms (2).jpg
This page was last modified on 17 July 2013, at 04:56.
115 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.