0

I want to send SMS programatically for that i am using below code but seems that it dontwork in 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?

Dattatray Deokar
  • 1,923
  • 2
  • 21
  • 31
  • What doesn't work? The docs for `SmsComposeTask` indicate it works on WP 8.1. – Ben Robinson Dec 01 '14 at 10:32
  • What is not working? Do you get any exception/error? Are you targeting *Silverlight* or *RunTIme*? Have you tried like [this](http://stackoverflow.com/a/23797884/2681948)? – Romasz Dec 01 '14 at 10:46
  • i am developing an universal application, visual studio dosent found any reference to it – Dattatray Deokar Dec 01 '14 at 10:54
  • i think this is workin 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); – Dattatray Deokar Dec 01 '14 at 10:56

2 Answers2

2
    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. You may want to check if cms is not null, just in case...

robcsi
  • 264
  • 3
  • 17
  • When I try this on a Lumia 550 running Windows 10 I get a `System.UnauthorizedAccessException` at the `SendMessageAsync` call. Any ideas on how to fix this? – Mellson Dec 31 '15 at 06:52
  • 1
    Figured it out. The app needed the restricted capability `cellularMessaging` as seen in the [docs here](https://msdn.microsoft.com/library/windows/apps/xaml/mt270968.aspx). – Mellson Dec 31 '15 at 09:13
1

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. 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 :)

Community
  • 1
  • 1
truongnm
  • 2,311
  • 2
  • 31
  • 48
  • This only composes the text message, but does not send it. – Sinaesthetic Jan 31 '15 at 22:37
  • @Sinaesthetic no way you could do that on windows phone. Simp 'cause the OS not allow that. – truongnm Feb 02 '15 at 12:33
  • I realize that. But it would have been useful to know in these posts while I was still figuring that out. The question was asking how to send, it probably would have been better to lead answers with "you can't actually send anything, only compose), so I wanted to make a note of it. I didn't down-vote or anything :) – Sinaesthetic Feb 02 '15 at 20:31
  • Please clarify "no way you could do that on windows phone". Do you mean it is impossible? How are other Apps doing this then if it's not possible? – MC9000 Apr 03 '16 at 11:04
  • If I remember right, back in those day, API was kinda strict, can you please name an app, and of couse please correct if I wrong. Tks. – truongnm Apr 03 '16 at 15:07