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


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


5661
2017-11-27 15:29


起源



答案:


请参阅以下链接中的教程

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);
        //}
    }
}

11
2017-11-27 15:41



如果您尝试在身体中发送超过140个字符会发生什么? - Beanwah
@Beanwah从未尝试过,但由于它是由默认提供的Task直接处理的,因此应该没有问题 - Harshit


答案:


请参阅以下链接中的教程

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);
        //}
    }
}

11
2017-11-27 15:41



如果您尝试在身体中发送超过140个字符会发生什么? - Beanwah
@Beanwah从未尝试过,但由于它是由默认提供的Task直接处理的,因此应该没有问题 - Harshit


从文档: 如何使用Windows Phone的SMS撰写任务


3
2018-03-18 20:35





要更清楚地使用此功能

//---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();
}

0
2017-07-14 04:17