SMS
This article describes how you can use the .NET Multi-platform App UI (.NET MAUI) ISms interface to open the default SMS app and preload it with a message and recipient.
The default implementation of the ISms
interface is available through the Sms.Default property. Both the ISms
interface and Sms
class are contained in the Microsoft.Maui.ApplicationModel.Communication
namespace.
Get started
To access the SMS functionality, the following platform specific setup is required.
If your project's Target Android version is set to Android 11 (R API 30) or higher, you must update your Android Manifest with queries that use Android's package visibility requirements.
In the Platforms/Android/AndroidManifest.xml file, add the following queries/intent
nodes in the manifest
node:
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="smsto"/>
</intent>
</queries>
Create a message
The SMS functionality works by creating a new SmsMessage object, and calling the ComposeAsync method. You can optionally include a message and zero or more recipients.
if (Sms.Default.IsComposeSupported)
{
string[] recipients = new[] { "000-000-0000" };
string text = "Hello, I'm interested in buying your vase.";
var message = new SmsMessage(text, recipients);
await Sms.Default.ComposeAsync(message);
}