11

是否可以在 Windows Phone 8 中以编程方式发送 SMS?我环顾四周,令我惊讶的是,没有找到任何东西......:s

4

3 回答 3

11

请参阅以下链接中的教程

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

这应该会有所帮助。请注意,最终发送 SMS 用户交互是必须的,您不能自动执行该操作。用户必须点击发送短信按钮

完整代码

    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);
        //}
    }
}
于 2012-11-27T15:41:11.657 回答
3

来自文档:How to use the SMS compose task for Windows Phone

于 2013-03-18T20:35:18.860 回答
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();
}
于 2015-07-14T04:17:15.153 回答