Dattatray Deokar
Dattatray Deokar

Reputation: 2103

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

   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?

Upvotes: 0

Views: 3295

Answers (2)

robcsi
robcsi

Reputation: 264

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

Upvotes: 2

truongnm
truongnm

Reputation: 2474

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

Upvotes: 1

Related Questions