Search code examples
androidemailpermissionsmaui

MAUI Email.ComposeAsync function call throws FeatureNotSupportedException on Android


I'm about to publish an application on Google Play, but my package was rejected because it uses this permission:

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

I included this permission in the AndroidManifest.xml because calling the Email.ComposeAsync function would result in a FeatureNotSupportedException without it.

        var message = new EmailMessage
        {
            Subject = $"Új funkció kérése / Hiba bejelentés ({AppInfo.AppName} {AppInfo.AppVersion})",
            Body = "Tisztelt Szoftverfejlesztő!\r\n\r\nKérés / hiba leírása...\r\n\r\nÜdvözlettel\r\n\r\n",
            To = [AppInfo.AppEmail],
            BodyFormat = EmailBodyFormat.PlainText
        };
        
        if (!String.IsNullOrEmpty(AppInfo.DevEmail))
        {
            message.Bcc = [AppInfo.DevEmail];
        }

        //await Email.Default.ComposeAsync(message).ConfigureAwait(false);
        await Email.ComposeAsync(message).ConfigureAwait(false);

I checked the documentation , and it doesn't specify which permission I should add for this function call to work or why it requires the QUERY_ALL_PACKAGES permission.

These are the exception details:

Microsoft.Maui.ApplicationModel.FeatureNotSupportedException

  • Message: Specified method is not supported.

Call stack:

  • 0xFFFFFFFFFFFFFFFF in Android.Runtime.RuntimeNativeMethods.monodroid_debugger_unhandled_exception C#
  • 0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:13,5 C#
  • 0x1D in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:27,26 C#
  • 0x17 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw C#
  • 0x6 in System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0 C#
  • 0xC in Android.App.SyncContext.<Post>b__8_0 at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:36,19 C#
  • 0xE in Java.Lang.Thread.RunnableImplementor.Run at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36,6 C#
  • 0x8 in Java.Lang.IRunnableInvoker.n_Run at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Java.Lang.IRunnable.cs:84,4 C#
  • 0x8 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:26,5 C#

The best approach would be to avoid using the QUERY_ALL_PACKAGES permission. Is there a possibility to do this?


Solution

  • according to the docs, you need to add this to the Android manifest

    <queries> 
      <intent> 
        <action android:name="android.intent.action.SENDTO" /> 
        <data android:scheme="mailto" /> 
      </intent> 
    </queries>