简体   繁体   English

如何在Windows Phone 8.1(C#)中以编程方式发送SMS

[英]How to send SMS programatically in Windows Phone 8.1(C#)

I want to send SMS programatically for that i am using below code but seems that it dontwork in 8.1 我想以编程方式发送短信,因为我正在使用以下代码,但似乎在8.1中不起作用

   SmsComposeTask SMSCompose = new SmsComposeTask();
   SMSCompose.To = "<Number to which the SMS needs to be sent";
   SMSCompose.Body = "Message that needs to be sent";
   SMSCompose.Show();

Is there any othey way to achive it? 有没有其他方法可以达到目标?

    public async static Task SendMessage (string phoneNumber)
    {
        ChatMessage msg = new ChatMessage();
        msg.MessageKind = Windows.ApplicationModel.Chat.ChatMessageKind.Standard;
        msg.Body = "...";
        msg.Recipients.Add(phoneNumber);
        ChatMessageStore cms = await ChatMessageManager.RequestStoreAsync();
        cms.SendMessageAsync(msg);
    }

This should send the message on Windows Phone 8.1. 这应该在Windows Phone 8.1上发送消息。 You may want to check if cms is not null, just in case... 您可能需要检查cms是否不为null,以防万一...

You should do some searching before make a new thread. 在创建新线程之前,您应该进行一些搜索。 Your question is already a part in this thread . 您的问题已经在该线程中 The universal app is also called windows runtime, so same solution in that threat if you want to send message or event call or send email. 通用应用程序也称为Windows运行时,因此如果您要发送消息或事件调用或发送电子邮件则可以在这种威胁中使用相同的解决方案。 You can use this for send message: 您可以将其用于发送消息:

Windows.ApplicationModel.Chat.ChatMessage msg = new Windows.ApplicationModel.Chat.ChatMessage();
msg.Body = "This is body of demo message.";
msg.Recipients.Add("10086");
msg.Recipients.Add("10010");
await Windows.ApplicationModel.Chat.ChatMessageManager.ShowComposeSmsMessageAsync(msg);

Enjoy coding! 享受编码!

P/s: update from @Sinaesthetic , this just compose the message, it'll not send it, all user has to do is to hit the send button :) P / s:从@Sinaesthetic更新,这只是编写消息,它不会发送,所有用户要做的就是点击发送按钮:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM