×
Namespaces

Variants
Actions

如何在Windows Phone 7上发送短信

From Nokia Developer 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" />
</Grid>

这是在XAML上写的代码,创建的页面将如下所示:

SmsMain.jpg

在MainPage.xaml.cs文件中,添加下面的代码:

.
.
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应用程序,短信内容和电话号码将通过上面的代码进行填充。

Sendsms.jpg

一旦用户在本地的SMS应用程序点击了“发送”按钮,短信将被发送。

Sentsms (2).jpg
This page was last modified on 17 July 2013, at 07:56.
92 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.

×