2012-11-27 109 views

回答

11

請參閱本教程在以下鏈接

http://www.windowsphonegeek.com/tips/How-to-compose-and-send-SMS-from-Windows-Phone-apps

這應該幫助。請注意,最終發送短信用戶互動是必須的,你不能自動化。用戶必須在發送短信按鈕點擊

全碼

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Navigation; 
using Microsoft.Phone.Controls; 
using Microsoft.Phone.Shell; 
using PhoneApp1.Resources; 
using Microsoft.Phone.Tasks; 

namespace PhoneApp1 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     // Constructor 
     public MainPage() 
     { 
      InitializeComponent(); 

      // Sample code to localize the ApplicationBar 
      //BuildLocalizedApplicationBar(); 
     } 

     private void Button_Click_1(object sender, RoutedEventArgs e) 
     { 
      SmsComposeTask smsComposeTask = new SmsComposeTask(); 

      smsComposeTask.To = _Number.Text; 
      smsComposeTask.Body = _Message.Text; 
      smsComposeTask.Show(); 
     } 

     // Sample code for building a localized ApplicationBar 
     //private void BuildLocalizedApplicationBar() 
     //{ 
     // // Set the page's ApplicationBar to a new instance of ApplicationBar. 
     // ApplicationBar = new ApplicationBar(); 

     // // Create a new button and set the text value to the localized string from AppResources. 
     // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); 
     // appBarButton.Text = AppResources.AppBarButtonText; 
     // ApplicationBar.Buttons.Add(appBarButton); 

     // // Create a new menu item with the localized string from AppResources. 
     // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); 
     // ApplicationBar.MenuItems.Add(appBarMenuItem); 
     //} 
    } 
} 
+0

如果你嘗試發送,會發生什麼身體中超過140個字符? – Beanwah

+0

@Beanwah從來沒有嘗試過,但由於它是由默認提供的任務直接處理,應該沒有問題 – Harshit

0

更清晰,使用此功能

//---sends an SMS message to another device--- 
private void sendSMS(String phoneNumber, String message) 
{ 
    SmsComposeTask smsComposeTask = new SmsComposeTask(); 
    smsComposeTask.To = phoneNumber; 
    smsComposeTask.Body = message; 
    smsComposeTask.Show(); 
} 
相關問題