mauimaui-blazor.net-9.0

How I can set SMS permissions?


I'm developing an application in Maui on .NET 9 that sends text messages. I've granted the SEND_SMS permission in the manifest and compiled the signed APK. However, on the phone, I can't activate the permission. It shows "wipeout" and if I try to activate it, it sends me to a page on how to activate it, but the process doesn't work.

​Code manifest:

<uses-permission android:name="android.permission.SEND_SMS" />

Solution

  • Since Android 10 (API level 29) and especially Android 11+, SMS permissions are considered high-risk

    So unless your app is set as the default SMS app, the SEND_SMS permission cannot be granted manually, and Android redirects users to an explanation page instead.


    1. Update AndroidManifest.xml

    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_MMS" />
    <uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
    
    <application ...>
        <receiver android:name="androidx.appcompat.content.WakefulBroadcastReceiver"
                  android:permission="android.permission.BROADCAST_SMS">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
    
        <!-- Required service and activity for SMS handling -->
    </application>
    

    2. Prompt User to Set Your App as Default SMS App

    using Android.Content;
    using Android.OS;
    using Android.Provider;
    
    public void RequestDefaultSmsApp()
    {
        if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
        {
            var intent = new Intent(Telephony.Sms.Intents.ActionChangeDefault);
            intent.PutExtra(Telephony.Sms.Intents.ExtraPackageName, Application.Context.PackageName);
            Application.Context.StartActivity(intent);
        }
    }
    

    3. Handle SMS with Full Responsibilities

    Once you're the default SMS app, you're responsible for:

    You can't just be a sender — Android expects full management.


    Or you can send SMS by using default SMS app

    var smsUri = Android.Net.Uri.Parse("smsto:1234567890");
    var smsIntent = new Intent(Intent.ActionSendto, smsUri);
    smsIntent.PutExtra("sms_body", "Hello from my app");
    StartActivity(smsIntent);