How to Send SMS on Xamarin.Forms
Asked Answered
G

2

11

I am developing Xamarin.Forms project, iOS, Android and Windows Phone.

My app ask the user to enter text Message and Phone number then on submit, I need to send SMS to the phone number.

I prefer to have a single implementation for all platforms.

Groundnut answered 14/2, 2017 at 15:6 Comment(0)
N
14

You can use this open source plugin Xam.Plugins.Messaging https://github.com/cjlotz/Xamarin.Plugins

This is the provided example (from https://github.com/cjlotz/Xamarin.Plugins/blob/master/Messaging/Details.md ) :

// Make Phone Call
var phoneDialer = CrossMessaging.Current.PhoneDialer;
if (phoneDialer.CanMakePhoneCall) 
    phoneDialer.MakePhoneCall("+272193343499");

// Send Sms
var smsMessenger = CrossMessaging.Current.SmsMessenger;
if (smsMessenger.CanSendSms)
   smsMessenger.SendSms("+27213894839493", "Well hello there from Xam.Messaging.Plugin");

var emailMessenger = CrossMessaging.Current.EmailMessenger;
if (emailMessenger.CanSendEmail)
{
    // Send simple e-mail to single receiver without attachments, bcc, cc etc.
    emailMessenger.SendEmail("[email protected]", "Xamarin Messaging Plugin", "Well hello there from Xam.Messaging.Plugin");

    // Alternatively use EmailBuilder fluent interface to construct more complex e-mail with multiple recipients, bcc, attachments etc. 
    var email = new EmailMessageBuilder()
      .To("[email protected]")
      .Cc("[email protected]")
      .Bcc(new[] { "[email protected]", "[email protected]" })
      .Subject("Xamarin Messaging Plugin")
      .Body("Well hello there from Xam.Messaging.Plugin")
      .Build();

    emailMessenger.SendEmail(email);
}   
Newberry answered 14/2, 2017 at 15:15 Comment(2)
Could you please add some code and add brief description that will make your answer more clear . Stackoverflow.com doest like URL . ThanksGroundnut
thanks alot, this is is clearly more than previous one.Groundnut
C
6

Microsoft now has this feature in their new all-encompasing https://learn.microsoft.com/en-us/xamarin/essentials NuGet package.

Chlorous answered 20/8, 2018 at 21:20 Comment(1)
@lan Vink could you pleaes make your question have more details than link .thxGroundnut

© 2022 - 2024 — McMap. All rights reserved.