如何在Windows Phone 7上发送短信

15 篇文章 0 订阅
14 篇文章 0 订阅
 
这篇文章展示了如何在Windows Phone 7应用程序中发送短信。
简介
这篇文章描述了如何在Windows Phone 7应用程序中发送短信。短信的发送是利用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上写的代码,创建的页面将如下所示: 
280px-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应用程序,短信内容和电话号码将通过上面的代码进行填充。 
282px-Sendsms.jpg 
一旦用户在本地的SMS应用程序点击了“发送”按钮,短信将被发送。
287px-Sentsms_%282%29.jpg 

 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值