以编程方式在Windows Phone 8中发送SMS

时间:2012-11-27 15:29:56

标签: windows-phone-8

是否可以在Windows Phone 8中以编程方式发送短信?我环顾四周,而且我的价格没有找到任何东西......:s

3 个答案:

答案 0 :(得分: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);
        //}
    }
}

答案 1 :(得分:3)

答案 2 :(得分: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();
}