Essentials: [Bug] Android 11 Sending Mail throws FeatureNotSupportedException

Created on 23 Sep 2020  路  15Comments  路  Source: xamarin/Essentials

Description

Calling await Email.ComposeAsync(mail); throws Xamarin.Essentials.FeatureNotSupportedException on Android 11.

Steps to Reproduce

  1. Create a blank Xamarin.Forms App
  2. Change Android Target Version to Android 11
  3. Try to send an email

Expected Behavior

Third party application is opend by Android and user can send mail.

Actual Behavior

A Xamarin.Essentials.FeatureNotSupportedException is thrown

Basic Information

  • Version with issue: 1.5.3.2
  • Last known good version: ---
  • IDE: Visual Studio 16.7.4
  • Platform Target Frameworks:

    • iOS: ---

    • Android: 11.0

    • UWP: ---

  • Nuget Packages: ---
  • Affected Devices: All Android 11 Devices and Emulator
bug

All 15 comments

Does it work on Android 10?

Also, you have a stack trace? Maybe something else is going wrong and some api was changed...

Yes, it works fine with Android 10 and lower. The StackTrace:

at Xamarin.Essentials.Email.ComposeAsync (Xamarin.Essentials.EmailMessage message) [0x00007] in d:\a\1\s\Xamarin.Essentials\Email\Email.shared.cs:21 
  at MailTestApp.MainPage.Button_OnPressed (System.Object sender, System.EventArgs e) [0x00053] in C:\Users\Name\source\repos\MailTestApp\MailTestApp\MailTestApp\MainPage.xaml.cs:30 

09-23 16:16:23.904 E/mono    (21071): Full thread dump:
"Debugger agent"


"<unnamed thread>"  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_boolean_method_a (intptr,intptr&,intptr,intptr,intptr,intptr) <0x00015>
  at Java.Interop.JniEnvironment/InstanceMethods.CallNonvirtualBooleanMethod (Java.Interop.JniObjectReference,Java.Interop.JniObjectReference,Java.Interop.JniMethodInfo,Java.Interop.JniArgumentValue*) [0x00079] in <42748fcc36b74733af2d9940a8f3cc8e>:0
  at Java.Interop.JniPeerMembers/JniInstanceMethods.InvokeVirtualBooleanMethod (string,Java.Interop.IJavaPeerable,Java.Interop.JniArgumentValue*) [0x0005f] in <42748fcc36b74733af2d9940a8f3cc8e>:0
  at Android.Views.View.DispatchTouchEvent (Android.Views.MotionEvent) [0x00038] in <227a96d68a0440cea172be41b1306654>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<TElement_REF>.DispatchTouchEvent (Android.Views.MotionEvent) [0x0001f] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:72
  at Xamarin.Forms.Platform.Android.Pla
tform/DefaultRenderer.DispatchTouchEvent (Android.Views.MotionEvent) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:1270
  at Android.Views.View.n_DispatchTouchEvent_Landroid_view_MotionEvent_ (intptr,intptr,intptr) [0x00011] in <227a96d68a0440cea172be41b1306654>:0
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.39 (intptr,intptr,intptr) [0x00017] in <227a96d68a0440cea172be41b1306654>:0
  at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.39 (intptr,intptr,intptr) [0x00032] in <227a96d68a0440cea172be41b1306654>:0
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_boolean_method_a (intptr,intptr&,intptr,intptr,intptr,intptr) <0x00015>
  at Java.Interop.JniEnvironment/InstanceMethods.CallNonvirtualBooleanMethod (Java.Interop.JniObjectReference,Java.Interop.JniObjectReference,Java.Interop.JniMethodInfo,Java.Interop.JniArgumentValue*) [0x00079] in <42748fcc36b74733af2d9940a8f3cc8e
>:0
  at Java.Interop.JniPeerMembers/JniInstanceMethods.InvokeVirtualBooleanMethod (string,Java.Interop.IJavaPeerable,Java.Interop.JniArgumentValue*) [0x0005f] in <42748fcc36b74733af2d9940a8f3cc8e>:0
  at Android.Views.View.DispatchTouchEvent (Android.Views.MotionEvent) [0x00038] in <227a96d68a0440cea172be41b1306654>:0
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<TElement_REF>.DispatchTouchEvent (Android.Views.MotionEvent) [0x0001f] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:72
  at Android.Views.View.n_DispatchTouchEvent_Landroid_view_MotionEvent_ (intptr,intptr,intptr) [0x00011] in <227a96d68a0440cea172be41b1306654>:0
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.39 (intptr,intptr,intptr) [0x00017] in <227a96d68a0440cea172be41b1306654>:0
  at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.39 (intptr,intptr,intptr) [0x00032] in <227a96d68a0440cea172be41b1306654>:0
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native
) Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_boolean_method_a (intptr,intptr&,intptr,intptr,intptr,intptr) <0x00015>
  at Java.Interop.JniEnvironment/InstanceMethods.CallNonvirtualBooleanMethod (Java.Interop.JniObjectReference,Java.Interop.JniObjectReference,Java.Interop.JniMethodInfo,Java.Interop.JniArgumentValue*) [0x00079] in <42748fcc36b74733af2d9940a8f3cc8e>:0
  at Java.Interop.JniPeerMembers/JniInstanceMethods.InvokeVirtualBooleanMethod (string,Java.Interop.IJavaPeerable,Java.Interop.JniArgumentValue*) [0x0005f] in <42748fcc36b74733af2d9940a8f3cc8e>:0
  at Android.Views.View.DispatchTouchEvent (Android.Views.MotionEvent) [0x00038] in <227a96d68a0440cea172be41b1306654>:0
  at Xamarin.Forms.Platform.Android.PlatformRenderer.DispatchTouchEvent (Android.Views.MotionEvent) [0x00035] in D:\a\1\s\Xamarin.Forms.Platform.Android\PlatformRenderer.cs:33
  at Android.Views.View.n_DispatchTouchEvent_Landroid_view_MotionEvent_ (intptr,intptr,intptr) [0x00011] in <227a96d68a0440cea172be41b1306654>:
0
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.39 (intptr,intptr,intptr) [0x00017] in <227a96d68a0440cea172be41b1306654>:0
  at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.39 (intptr,intptr,intptr) [0x00032] in <227a96d68a0440cea172be41b1306654>:0

"Finalizer"
09-23 16:16:33.920 I/libc    (21071): Requested dump for tid 21071 (ame.mailtestapp)

I think the problem could be the API Change for Android 10. In your csproj file "monoandroid10.0" is directly addressed, also with precompiler flags. Therefore the code with Android 11 Targetframework is executed on removed API Parts.

Issue #1391 looks simular to this problem.

Is this with an Attachment?

In this case not. But it doesn鈥榯 matter, I tested it with no attachment, single and multiple. Always same behavior.

Interesting... yeah cause it shouldn't use the file provider at all then.

Was there anything else in the stack trace?

Did some testing with the sample app in the repo with an R emulator.

  • Target 10/Compile 10 it works.
  • Target 11/Compile 11 throws exception because manager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly); return 0.

Something obviously changes in the API when targeting 11, which is becuase..... Google introduce Package Visibility 馃憤
https://stackoverflow.com/questions/62535856/intent-resolveactivity-returns-null-in-api-30
https://developer.android.com/preview/privacy/package-visibility

add the following into your AndroidManifest.xml

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

https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9

we may need to do some work for chrome custom tabs....

Is this supported @jonathanpeppers ? I get a build error ->

Severity    Code    Description Project File    Line    Suppression State
Error       ADB0010:  Deployment failed
Mono.AndroidTools.InstallFailedException: Unexpected install output: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl1401922127.tmp/base.apk (at Binary XML file line #16): intent tag may have at most one action.]

   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
   at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass97_0.<InstallPackage>b__0(Task`1 t)
   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Xamarin.AndroidTools.AndroidDeploySession.<InstallPackage>d__116.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Xamarin.AndroidTools.AndroidDeploySession.<RunAsync>d__110.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.AndroidTools.AndroidDeploySession.<RunLoggedAsync>d__108.MoveNext()           0   

W

@jamesmontemagno can you send me the project you're building?

I tried putting the <queries> element above in a new project and it was working for me -- even on an API 21 emulator.

We had to work around some things in API 30 for <queries>, but this is probably unrelated:

I have the same problem as @jamesmontemagno mentioned, getting same Exception. I tried it out with an empty project. If I adding the <queries> tags in the android manifest, i can't deploy... (Target Version API 30)

Ok, it only happens on API 30 emulator. I changed the AndroidManifest.xml to this and it installs:

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

If you run into this:

ADB1000:  Deployment failed Xamarin.AndroidTools.AndroidDeploymentException: FailedToSynchronizeFastDevAssemblies --->
Mono.AndroidTools.AdbException: secure_mkdirs failed: Permission denied

This can be worked around by turning off Use Shared Runtime & Use Fast Deployment. We have a fix coming in a future 16.8 preview.

Ahhh, yeah their documentation is not great on this topic surprisingly lol. i will be updating the docs as well for this :)

Lovely!!! Here is your final stuff you need to add:

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

This handles email, sms, and browser

@jonathanpeppers can we do this with assembly attributes?

Thanks, its works!

I just ran into this issue after releasing an app to the store. 馃槵 Adding those intents will solve it?

They should. This should also only be happening on Android 11.

Was this page helpful?
0 / 5 - 0 ratings