Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Java Security Exception when launching email client from Android dependency service

$
0
0

Hi,

I created a simple Xamarin.Forms dependency service in Android to launch the email composer but I'm getting a java security exception when executing the code below. I checked but there's no specific Android permission for writing emails... x

Any suggestions appreciated.

Thanks!

[assembly: Xamarin.Forms.Dependency (typeof (MyApp.Droid.Interfaces.EmailSender_Android))]

namespace MyApp.Droid.Interfaces
{
    public class EmailSender_Android : Java.Lang.Object, IEmailSender
    {

        // Constructor
        public EmailSender_Android() { }

        // Send Email 
        public bool Send(string recipientEmailAddress, string subject, string message) {
            bool ret = true;

            // Get the context
            var ctx = Forms.Context;

            // Create Email Intent
            var intent = new Intent (Intent.ActionSend);

            // Set Recipient
            intent.PutExtra(Intent.ExtraEmail, new string[] { recipientEmailAddress });

            // Set Email Subject
            intent.PutExtra(Intent.ExtraSubject, subject);

            try {

                Forms.Context.StartActivity(intent);
                ret = true;
            } catch (Exception ex) {
                Console.WriteLine (ex.Message);
                ret = false;
            }
            return ret;
        }

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>